The IOS UI Learning Tutorial uses Uiimageview controls to make animations _ios

Source: Internet
Author: User

This example for you to share the iOS using Uiimageview control animation method for your reference, the specific content as follows

Add 40 tomcat pictures to the list of resources: The name is cat_eat0000.jpg to Cat_eat0039.jpg.
1, define the required controls

  define buttons, picture controls, variable array objects
  UIButton *actionbuttom;
  Uiimageview *imagemove;
  Nsmutablearray *imgsarray;

2. Initialize each control

Image Animation//initialization uiimageview, size and view of the same size imagemove = [[Uiimageview alloc]initwithframe:self.view.frame];
Sets the initialization picture of the Uiimageview imagemove.image = [uiimage imagenamed:@ "cat_eat0000.jpg"];
Load the Uiimageview onto the page [Self.view Addsubview:imagemove];  
  
Sets the interactivity of the Uiimageview to Yes imagemove.userinteractionenabled = yes;
Create Function button//Initialize button Actionbuttom = [[UIButton alloc]initwithframe:cgrectmake (100, 680, 218, 50)];
Set button background color Actionbuttom.backgroundcolor = [Uicolor Yellowcolor];
Set button title [Actionbuttom settitle:@ "start playing" forstate:uicontrolstatenormal];
Set button text color [Actionbuttom settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal]; To add a trigger event for a button [Actionbuttom addtarget:self action: @selector (startmove:) forcontrolevents:uicontroleventtouchupinside
];
  
  
  
Add the button to the page [Imagemove Addsubview:actionbuttom];
Initializes the variable group, which is used to store the picture Imgsarray = [[Nsmutablearray alloc]initwithcapacity:40];
  The loop gets 40 pictures from the resource and adds it to the Imgsarray. for (int x=0; x<40; x + +) {NSString *imgname = [NSString stringwithformat:@ "Cat_eat00%.2d.jpg", X];
    UIImage *img = [UIImage imagenamed:imgname]; [Imgsarray addobject:img];

3, set the button to trigger animation playback

Button trigger event
-(void) Startmove: (ID) sender{
//  Set animation length
  imagemove.animationduration = 2;  sets the animation picture source for the picture array
  imagemove.animationimages = Imgsarray;  Set animation Repeat number, 0 is infinite loop, 1 is repeat 1 times
  imagemove.animationrepeatcount = 1;  start playing
  [Imagemove startanimating];
  
}

The above is the entire content of this article, I hope to learn how to use Uiimageview control to make animation help.

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.