Iphone exercises for image switching (implemented by code)

Source: Internet
Author: User

:
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)

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.