ImageView animation, image viewer

So, I want to animate the UIImageView on the loading screen, and I was told that the built-in "animationImages" method takes up a lot of memory and does not program well, so I will not use it, I also had problems with this, besides this, moreover.

The code below almost works, but it animates too quickly, even if I put 3 seconds.

func animate() { UIView.animateWithDuration(3, animations: { () -> Void in self.logoImageView.image = UIImage(named: "00") self.logoImageView.image = UIImage(named: "02") self.logoImageView.image = UIImage(named: "03") self.logoImageView.image = UIImage(named: "04") self.logoImageView.image = UIImage(named: "05") self.logoImageView.image = UIImage(named: "06") self.logoImageView.image = UIImage(named: "07") self.logoImageView.image = UIImage(named: "08") self.logoImageView.image = UIImage(named: "09") self.logoImageView.image = UIImage(named: "10") self.logoImageView.image = UIImage(named: "11") self.logoImageView.image = UIImage(named: "12") self.logoImageView.image = UIImage(named: "13") self.logoImageView.image = UIImage(named: "14") self.logoImageView.image = UIImage(named: "15") self.logoImageView.image = UIImage(named: "16") self.logoImageView.image = UIImage(named: "17") self.logoImageView.image = UIImage(named: "18") self.logoImageView.image = UIImage(named: "19") self.logoImageView.image = UIImage(named: "20") self.logoImageView.image = UIImage(named: "21") self.logoImageView.image = UIImage(named: "22") self.logoImageView.image = UIImage(named: "23") self.logoImageView.image = UIImage(named: "24") self.logoImageView.image = UIImage(named: "25") self.logoImageView.image = UIImage(named: "26") }) { (success) -> Void in self.fadeInLabel() } 

However, the code below disappears on the welcome label and works fine, so I wonder what the problem is with the above. Thanks for the help!

 func fadeInLabel() { UIView.animateWithDuration(2, animations: { () -> Void in self.labelImageView.alpha = 1 }) { (success) -> Void in self.performSelector("pushToCreateVC", withObject: self, afterDelay: 1) } } 
+5
source share
2 answers

If u wants to animate images, you can use the animationImages property of UIImageView

 self.logoImageView.animationImages = imagesListArray; self.logoImageView.animationDuration = 3.0 self.logoImageView.startAnimating() 

where imagesListArray is an array of images that want to animate

OR

If you want to animate images using custom animation, you can use the code below where I used the animation option UIViewAnimationOptionTransitionFlipFromLeft . The code in Obj-C, hope you can display the semantics.

 // in view Load _slide = 0 [self changeSlide]; // Loop gallery NSTimer *timer = [NSTimer timerWithTimeInterval:5.0f target:self selector:@selector(changeSlide) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; - (void)changeSlide { if(_slide > _galleryImages.count-1) _slide = 0; UIImage *toImage = [UIImage imageNamed:_galleryImages[_slide]]; [UIView transitionWithView:_yourimageView duration:0.6f options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{ _yourimageView.image = toImage; } completion:nil]; _slide++; } 
+3
source

I am having a problem with the animationImages method, which returns the View image back to the original image when completed. I'm not sure if there is a better way, but I ended up using a timer so that ImageView saves the last image after completion.

 var counter = 0 var timer = NSTimer() @IBAction func countButton(sender: UIButton) { timer.invalidate() timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "timerAction", userInfo: nil, repeats: true) } func timerAction() { ++counter switch counter{ case 1 : image1.image = UIImage(named:"Bird-1.gif") case 2 : image1.image = UIImage(named:"Bird-2.gif") case 3 : image1.image = UIImage(named:"Bird-3.gif") case 4 : image1.image = UIImage(named:"Bird-4.gif") case 5 : image1.image = UIImage(named:"Bird-5.gif") case 6 : counter = 0 timer.invalidate() default : print("Error") } } 
0
source

Source: https://habr.com/ru/post/1236015/


All Articles