------------- viewcontroller.m -------------
#import "ViewController.h"
@interface viewcontroller ()
@property (weak, nonatomic) iboutlet uiimageview *imageview;
-(ibaction) drink;
-(ibaction) konckout;
-(ibaction) footleft;
@end
@implementation Viewcontroller
-(ibaction) drink
{
[ Self Playanimationwithimagename: Span style= "font-variant-ligatures:no-common-ligatures; Color: #d12f1b ">@" Drink " andimagecount: 81 ";
}
-(ibaction) konckout
{
[ Self Playanimationwithimagename: Span style= "font-variant-ligatures:no-common-ligatures; Color: #d12f1b ">@" Knockout " andimagecount: 81 ";
}
-(ibaction) footleft
{
[ Self Playanimationwithimagename: Span style= "font-variant-ligatures:no-common-ligatures; Color: #d12f1b ">@" Footleft " andimagecount: 30 ";
}
-(void) Playanimationwithimagename: (nsstring *) imageName andimagecount: (nsinteger) Count
{
if(self. ImageView . Isanimating)
{
return;
}
nsmutablearray *images = [nsmutablearray array];
for (int i = 0; i < count; i++)
{
nsstring *name = [ nsstring stringwithformat : @ "%@_%02d.jpg" , imagename,i];
nsstring *path = [[ nsbundle mainbundle ] Pathforresource : Name oftype : nil ];
UIImage *image = [UIImage imagewithcontentsoffile:p Ath];
[Images AddObject: image];
}
Self. ImageView. animationimages = images;
Self. ImageView. animationduration = 0.05 * count;
Self . imageview Animationrepeatcount = 1 ;
[self. ImageView startanimating];
you need to clear animationimages when the animation has finished playing
// the first way:
[ Self Performselector:@selector(clearimages)Withobject:Nil Afterdelay: Self.ImageView.animationduration];
// second Way
[Self.imageview performselector: @selector (setanimationimages:) Withobject:nil Afterdelay: Self.imageView.animationDuration];
// Third Way
Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (Self.imageView.animationDuration * nsec_per_sec)), Dispatch_get_main_queue (), ^{
Self.imageView.animationImages = nil;
// });
}
-(void) clearimages
{
self. ImageView . Animationimages = nil;
}
@end
17. Small item: Tom Cat version 3.0