UIImageView comes with animations + N images to achieve dazzling animations,

Source: Internet
Author: User

UIImageView comes with animations + N images to achieve dazzling animations,

GitHub saw a Very dazzling Animation: https://github.com/MartinRGB/GiftCard-iOS looked at his code, found the core animation (is to wrap the button into a gift box) is actually very simple, the method is to take all frames of an animation and place them in an array, and then use the method that comes with UIImageView to play an array of images. The simplified code is like this:-(void) viewDidLoad {[super viewDidLoad]; NSMutableArray * array = [NSMutableArray array]; for (int I = 0; I <40; I ++ ){
UIImage * image = [UIImage imageNamed: [NSString stringWithFormat: @ "gifbutton000% 02d", I];
[Array addObject: image];
}
Self.gif tImageArray = array;
Self.gif tImageView. animationDuration = 1.0;
Self.gif tImageView. animationImages = self.gif tImageArray;
Self.gif tImageView. animationRepeatCount = 1;
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handleGiftImageViewTapped :)];
[Self.gif tImageView addGestureRecognizer: tapGesture];
Self.gif tImageView. userInteractionEnabled = YES;
Self.gif tImageView. image = paiself.gif tImageArray firstObject];
}-(Void) handleGiftImageViewTapped :( UITapGestureRecognizer *) sender {
[Self.gif tImageView startAnimating];
Dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t) (1 * NSEC_PER_SEC), dispatch_get_main_queue (), ^ {
UIImage * image = paiself.gif tImageArray lastObject];
Self.gif tImageView. image = image;
});} Although the effect method is simple, the effect is very good. I don't know if there is any better implementation method, but it is at least a implementation method, which is worth record!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.