The IOS UI tutorial USES the UIImageView control to animate
- 2020-05-27 07:16:34
- OfStack
The example of this article is to share the animation method of IOS using UIImageView control, for your reference, the specific content is as follows
Start by adding 40 tomcat images to the resource list: name cat_eat0000. jpg to cat_eat0039.jpg.
1. Define the required controls
// Define buttons, image controls, and mutable array objects
UIButton *actionbuttom;
UIImageView *imageMove;
NSMutableArray *imgsarray;
2. Initialize each control
// image animation
// Initialize the UIImageView , size, and View The same size
imageMove = [[UIImageView alloc]initWithFrame:self.view.frame];
// Set up the UIImageView Initializes the image
imageMove.image = [UIImage imageNamed:@"cat_eat0000.jpg"];
// the UIImageView Load to page
[self.view addSubview:imageMove];
// Set up the UIImageView The interactivity is yes
imageMove.userInteractionEnabled = YES;
// Create function button
// Initialization button
actionbuttom = [[UIButton alloc]initWithFrame:CGRectMake(100, 680, 218, 50)];
// Set the background color of the button
actionbuttom.backgroundColor = [UIColor yellowColor];
// Set the button title
[actionbuttom setTitle:@" Start playing " forState:UIControlStateNormal];
// Set the color of the button text
[actionbuttom setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// Add a trigger event to the button
[actionbuttom addTarget:self action:@selector(startmove:) forControlEvents:UIControlEventTouchUpInside];
// Add the button to the page
[imageMove addSubview:actionbuttom];
// Initializes a mutable array to hold images
imgsarray = [[NSMutableArray alloc]initWithCapacity:40];
// The loop takes it from the resource 410 Take a picture and add it to 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 the animation
// Button trigger event
-(void)startmove:(id)sender{
// Set animation duration
imageMove.animationDuration = 2;
// Sets the animated image source to an array of images
imageMove.animationImages = imgsarray;
// Set the number of animation repeats, 0 It's an infinite loop, 1 To repeat 1 time
imageMove.animationRepeatCount = 1;
// Start playing
[imageMove startAnimating];
}
That is the end of this article, I hope to help you learn to use the UIImageView control animation.