So I want to animate a UIImageView on a load screen and I've been told that the built in "animationImages" method takes up a lot of memory and is bad programming so I won't use that, I also had issues with it but that's besides the point.
The code below almost works but it animates through way too fast even though 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 here fades in the welcome label and works just fine so I wonder what the issue with the above is. 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)
}
}
If u want to animate images u can use animationImages
property of UIImageView
self.logoImageView.animationImages = imagesListArray;
self.logoImageView.animationDuration = 3.0
self.logoImageView.startAnimating()
where imagesListArray
is array of images u want to animate
OR
If u want to animate the images with custom animation u can use below code where i used UIViewAnimationOptionTransitionFlipFromLeft
animation option.Belowcode is in Obj-C , I hope u can map the semantic.
// 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++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With