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!