ios--uiimageview--Frame Animation

Source: Internet
Author: User

Frame animation
    • Because there is no study of the production of GIF, so can only cut a few pictures to see the < How to make a Mac on the gif>

Play method
    • Load all animated pictures
    • Set up animated pictures
    • Set the number of plays
    • Set up a picture
    • Set animation time
    • Start animation
    • How to perform after playback is complete
- (void) Play: (NSString*) Filenameprefix Count: (int) count{//load all animated pictures    Nsmutablearray*images = [NsmutablearrayArray]; for(inti =1; i<=count; i++) {NSString*filename = [NSStringstringwithformat:@"%@_%d", Filenameprefix, I];NSString*file = [[NSBundleMainbundle] Pathforresource:filename oftype:@"PNG"];UIImage*image = [UIImageImagewithcontentsoffile:file];    [Images Addobject:image]; }//Set animated pictures     Self. ImageView. Animationimages= images;//Set the number of plays     Self. ImageView. Animationrepeatcount= [Filenameprefix isequaltostring:@"Stand"] ?0:1;//Set Picture     Self. ImageView. Image= [UIImageimagenamed:@"Stand_1"];//Set the animation time     Self. ImageView. Animationduration= Count *0.04;//Start animation[ Self. ImageViewStartanimating];if([Filenameprefix isequaltostring:@"Stand"])return;//After playing the animation stand (The stand method of calling self after delaying self.imageView.animationDuration time)[ SelfPerformselector:@selector(stand) Withobject:NilAfterdelay: Self. ImageView. Animationduration];}
Simple Load Audio
    • Steps
      • Import Audio Header file
      • Create Audio properties
      • Create a URL for an audio file
      • Create player
      • Start playback
#import <AVFoundation/AVFoundation.h>@property (strongnonatomic) AVPlayer *player;// 创建一个音频文件的URL(URL就是文件路径对象)NSURL *url = [[NSBundle mainBundle] URLForResource:@"dazhao" withExtension:@"mp3"];// 创建播放器self.player = [AVPlayer playerWithURL:url];// 播放[self.player play];
Source
////VIEWCONTROLLER.M//Fist frame animation////Created by Macbookpro on 15/8/9.//Copyright 2015 sky5156. All rights reserved.//#import "ViewController.h" #import <AVFoundation/AVFoundation.h>  @interface viewcontroller ()//Get the ImageView in storyboard@property(Weak,nonatomic)Iboutlet Uiimageview*imageview;//Put some music on@property(nonatomic,Strong) Avplayer *player;@end @implementation viewcontroller - (void) Viewdidload {[SuperViewdidload];//Add a borderCalayer *layer = [ Self. ImageViewLayer]; Layer. BorderColor= [UicolorRedcolor]. Cgcolor; Layer. BorderWidth=5.0F [ SelfStand];} - (ibaction) Stand {[ Selfplay:@"Stand"CountTen];} - (ibaction) Dead {[ Selfplay:@"Dead"Count at];} - (ibaction) Run {[ Selfplay:@"Run"Count6];} - (ibaction) Xiaozhao {[ Selfplay:@"Xiaozhao1"Count -]; [ Selfplaymusic:@"Xiaozhao1"]; [ SelfPerformselector:@selector(XIAOZHAO2) Withobject:NilAfterdelay: -*0.06];//[Self play:@ "Xiaozhao3" count:39];}- (ibaction) Dazhao {[ Selfplay:@"Dazhao"Count the]; [ Selfplaymusic:@"Dazhao"];} - (ibaction) Install_b {[ Selfplay:@"Install_b"Count in];} - (void) xiaozhao2{[ Selfplay:@"Xiaozhao2"Count *]; [ Selfplaymusic:@"Xiaozhao2"]; [ SelfPerformselector:@selector(XIAOZHAO3) Withobject:NilAfterdelay: **0.06];} -(void) xiaozhao3{[ Selfplay:@"Xiaozhao3"Count the]; [ Selfplaymusic:@"Xiaozhao3"];} - (void) Playmusic: (NSString*) music{NSString*urlstring = [NSStringstringwithformat:@"%@", music];//NSString *urlname = [[NSBundle mainbundle] pathforresource:urlstring oftype:@ "MP3"];    Nsurl*url = [[NSBundleMainbundle] Urlforresource:urlstring withextension:@"MP3"]; Self. Player= [Avplayer Playerwithurl:url]; [ Self. PlayerPlay];} - (void) Play: (NSString*) Prefixname Count: (int) count{//Loading animations    Nsmutablearray*images = [NsmutablearrayArray]; for(inti =1; i<=count; i++) {NSString*filename = [NSStringstringwithformat:@"%@_%d", Prefixname,i];NSString*name = [[NSBundleMainbundle] Pathforresource:filename oftype:@"PNG"];UIImage*image = [UIImageImagewithcontentsoffile:name];    [Images Addobject:image]; }//Set the animation     Self. ImageView. Animationimages= images; Self. ImageView. Image= [UIImageimagenamed:@"Stand_1"]; Self. ImageView. Animationrepeatcount= [Prefixname isequaltostring:@"Stand"]?0:1; Self. ImageView. Animationduration= count*0.06; [ Self. ImageViewStartanimating];//Stand after playing    if([Prefixname isequaltostring:@"Stand"])return; [ SelfPerformselector:@selector(stand) Withobject:NilAfterdelay:count *0.06];}@end
    • GitHub Source code Address:
      Https://github.com/LGLee/FrameAnimation

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ios--uiimageview--Frame Animation

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.