:
Switch:
Create a view-based project named Animation2 and add several images to the project !!
Directly implement the Code in Animation2ViewController. m:
-(Void) viewDidLoad
{
// Define an array to store all image objects
NSArray * images = [NSArray images: [UIImage imageNamed: @ "xuanyi.jpg"], [UIImage imageNamed: @ "xigua.jpg"], [UIImage imageNamed: @ "juhua.jpg"], [UIImage imageNamed: @ "heihua.jpg"], [UIImage imageNamed: @ "cell.jpg"], nil];
// Define the struct and block size
CGRect frame = CGRectMake (0, 0,320,460 );
// Initialize the Image view object. The size is frame.
UIImageView * imageView = [[UIImageView alloc] initWithFrame: frame];
// The Animated Image of imageView is an array of images
ImageView. animationImages = images;
// Scale the image according to the original proportion to maintain the aspect ratio.
ImageView. contentMode = UIViewContentModeScaleAspectFit;
// The switching time is 3 seconds to control how fast the image is displayed,
ImageView. animationDuration = 3;
// The number of animation repetitions. If you want to make it infinite loop, it is assigned 0.
ImageView. animationRepeatCount = 0;
// Start the animation www.2cto.com
[ImageView startAnimating];
// Add controls
[Self. view addSubview: imageView];
// Release the memory
[ImageView release];
[Super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(Void) viewDidLoad
{
// Define an array to store all image objects
NSArray * images = [NSArray images: [UIImage imageNamed: @ "xuanyi.jpg"], [UIImage imageNamed: @ "xigua.jpg"], [UIImage imageNamed: @ "juhua.jpg"], [UIImage imageNamed: @ "heihua.jpg"], [UIImage imageNamed: @ "cell.jpg"], nil];
// Define the struct and block size
CGRect frame = CGRectMake (0, 0,320,460 );
// Initialize the Image view object. The size is frame.
UIImageView * imageView = [[UIImageView alloc] initWithFrame: frame];
// The Animated Image of imageView is an array of images
ImageView. animationImages = images;
// Scale the image according to the original proportion to maintain the aspect ratio.
ImageView. contentMode = UIViewContentModeScaleAspectFit;
// The switching time is 3 seconds to control how fast the image is displayed,
ImageView. animationDuration = 3;
// The number of animation repetitions. If you want to make it infinite loop, it is assigned 0.
ImageView. animationRepeatCount = 0;
// Start the animation
[ImageView startAnimating];
// Add controls
[Self. view addSubview: imageView];
// Release the memory
[ImageView release];
[Super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
OK. Switch images !!
OK! Implementation! This blog is my own exercise. I have not explained many things clearly. Please forgive me!
From Ren haili (3G/mobile development)