-1

I'm creating an animation inside of an iOS application where a shape gets bigger and rotates. I've created the images so they have different sizes inside my photo editor, but when I animate them, they stay at whatever size the very first image is. Here is my current test code:

class ViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!
var images = [UIImage]()
var images2 = [UIImage]()


images += [#imageLiteral(resourceName: "circle1"), #imageLiteral(resourceName: "circle2"), #imageLiteral(resourceName: "circle3"), #imageLiteral(resourceName: "circle4")]
images2 += [#imageLiteral(resourceName: "circle4"), #imageLiteral(resourceName: "circle3"), #imageLiteral(resourceName: "circle2"), #imageLiteral(resourceName: "circle1")]

override func viewDidLoad() {
    super.viewDidLoad()


    imageView.animationImages = images
    imageView.animationDuration = 4.0

}

 @IBAction func startButton(_ sender: UIButton) {
    imageView.startAnimating()

    self.perform(#selector(ViewController.secondAnimation), with: nil, afterDelay: 0.9)
}

func secondAnimation() {
     imageView.stopAnimating()
     imageView.animationImages = images2
     imageView.animationDuration = 6.0
     imageView.animationRepeatCount = 1
     imageView.startAnimating()
 }

The images that have lower resolution are stretched and are pixelated to match the size of the other photos. They all have the same relative size on the user interface (UIImageView). If I reverse the order of the animation, the images being animated are being set to the default size of the first photo again that are of the different size, so I'm certain the animation is using the first image size to set default size on the display.

To simplify my problem as much as possible, the animation is showing the changed resolution, but not showing the proper relative size change of each image. Why is this happening?

schulzey
  • 95
  • 1
  • 2
  • 9

1 Answers1

0

If you want to use gif like animation, then you can forget about the iOS animation. Do everything in pic edit. What you need to do is edit the pictures, not the code. Make all the pics in same size, for the "smaller" ones, use clear color as background color.

To do animation in iOS, here is some sample code:

UIView.animate(withDuration: 0.5) { 
    var t = self.image.transform
    t = t.scaledBy(x: 1.3, y: 1.3)
    t = t.rotated(by: CGFloat(M_PI_4))
    self.image.transform = t;
}
jokeman
  • 1,277
  • 9
  • 22
  • Okay, so this definitely takes a lot of the work out of what I'm doing, because then I can use just one image correct? – schulzey Jan 25 '17 at 22:48
  • The only problem with this is my animation has multiple moving parts (I'm creating an animation with inkscape and choosing frame by frame the animation). This rotates and changes the size of the entire image. I just need the `startAnimate()` method to be able to allow my image size changes to show. – schulzey Jan 25 '17 at 22:50
  • I just came to this conclusion as well. I was just reducing the overall image size thinking that it would be the fastest way to modify dozens of photos to give a zooming effect. Since I have multiple moving parts in my photos, is pic edit the only way to do what I want? – schulzey Jan 25 '17 at 23:55
  • Also, can you post the code again for programmatically zooming and rotating an image? That was cool and I may use that in another project. thanks! – schulzey Jan 25 '17 at 23:56
  • @schulzey AFAIK, that's easiest way to insert a small "video" in your view. – jokeman Jan 26 '17 at 01:24