animate image once using SwiftGifOrigin swift4 - ios

I am trying to animate once using SwiftGifOrigin pod but it does not work, using .loadgif the image can animate unlimited times but I want to animate image once
image outlet
#IBOutlet weak var gifimage: UIImageView!
using this method image animate unlimited times
gifimage.loadGif(name: "1_splash1")
and using this method nothing happened it does not show any image
let animated_image = UIImage.gif(name: "1_splash1")
gifimage.animationImages = animated_image?.images
gifimage.animationDuration = (animated_image?.duration)!
gifimage.animationRepeatCount = 1
gifimage.startAnimating()

Related

Take ARSCNView snapshot with subview

I am using ARSCNView.snapshot() to take a snapshot in my iOS app with a picture as a frame. The picture frame is a UIImageView which is a subview to the ARSCNView. However, I can only get the scene in the taken picture without the image. I also tried to use this method (https://stackoverflow.com/a/45346555/10057340) to render the ARSCNView as an image but I only got the image frame with a white background rather than the image frame with the camera scene. Can anyone suggest a way for doing this? Thanks!!
Below is how I used snaphot():
var frameImageView: UIImageView!
var sceneView: ARSCNView!
func takeSnapShot() {
frameImageView.image = UIImage(named:"frame")
frameImageView.ishidden = false
sceneView.addSubView(frameImageView)
UIImageWriteToSavedPhotosAlbum(sceneView.snapshot(), nil, nil. nil)
}
I don't fully understand what you are asking specifically but you might find this video from the WWDC 2017 useful: https://www.youtube.com/watch?v=eBt1p799L3Q
Check out the project they make at 18 min.

Adding custom sprite object to a view

I'm making a game and built a custom NSObject sprite class for it. What I want to do is when my view loads add a visual representation of my object. I don't think it should be that hard but this is my first time trying to get a custom class to render on the screen. Also I want to do this without using Sprite Kit. Here is a stripped down version of what my sprite class looks like.
class sprite: NSObject {
var img: UIImage = UIImage(named: "koalio_stand")!
var width = 10
var height = 10
var x, y: Int!
var velocity: Int!
}

Xcode - Animating with PNG sequence

I have made an animation with After Effect and added it to my Xcode project as a PNG sequence. This leave me with a folder with 164 images, i am animating with a timer. How is that for the app performance? And could i add more animations like this without any problem?
if its images,
first get those images in an array
#IBOutlet weak var animatingImageView: UIImageView!
var imageList = [UIImage]()
now call function
func playAnimation() {
self.animatingImageView.animationImages = imageList
self.animatingImageView.animationDuration = 2.0
self.animatingImageView.startAnimating()
}
you can use
self.animatingImageView. animationRepeatCount
for repeat count,
and also, if you want to stop it after some time interval, do it with a timer, and on timer completion
self.animatingImageView.stopAnimating()
for better performance:
try using image of size close to the imageview
try using cached image
try making image opaque

Change filter intensity like brightness from 0 to 100 via slider control in gpuimage2 swift

I followed the example of changing filter intensity on video camera from GPUImage2 examples, I am trying to change the filter intensity on a static image with iOS slider control, but it's not changing the intensity.
#IBOutlet weak var renderView: RenderView!
var filterContrast:ContrastAdjustment!
#IBOutlet weak var sliderContrast: UISlider!
let inputImage = UIImage(named:"WID-small.jpg")!
var picture:PictureInput!
// setting dynamic observable property.
dynamic var filterValue = 3.0 {
didSet {
filterContrast.contrast = GLfloat(filterValue)
picture.processImage()
}
}
on viewDidLayoutSubviews
picture = PictureInput(image: inputImage)
filterContrast = ContrastAdjustment();
picture --> filterContrast --> renderView
filterValue = 3; // will call did set property and call processimage from it
on Slider Update
filterValue = Double(nm);
is there any thing wrong, with this approach?
Thanks
Every time your slider value changes, you're creating a new ContrastAdjustment filter instance and attaching it to the picture. Your old filter instance is still there, and the RenderView will ignore any inputs beyond the first one that goes into it. In fact, you should have been seeing warnings on the console telling you about that fact that you're adding too many inputs to the RenderView.
Instead of creating a whole new ContrastAdjustment filter each time, simply save your contrast filter as an instance variable and adjust its contrast property when the slider changes.

Animation by PNG frames

I have several PNG images that if it will be presented one after the other they will create a short animation.
My question is -
Is possible to create an animation with several PNG images, by displaying them one after the other?
Yes you can create animation with pngs,
let animationImagesArray : [UIImage] = [<Add images>]
imageView.animationImages = animationImagesArray
imageView.startAnimating()
You can also set repeat count and animation duration as well.
Update
To load sequence of images via loop its better you name them in a sequence some thing like this (animationImage1.png, animationImage2.png...)
for i in 0..<20
{
let name = "\(prefix)_\(i).png"
let image = UIImage(named: name)!
images.append(image)
}

Resources