:
3秒切換到:
建立一個基於視圖的項目,命名為Animation2,往項目中放入幾個圖片!!
直接在Animation2ViewController.m中實現代碼:
- (void)viewDidLoad
{
//定義數組,存放所有圖片對象
NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"xuanyi.jpg"],[UIImage imageNamed:@"xigua.jpg"],[UIImage imageNamed:@"juhua.jpg"],[UIImage imageNamed:@"heihua.jpg"],[UIImage imageNamed:@"cell.jpg"], nil];
//定義結構體,方塊大小
CGRect frame=CGRectMake(0, 0, 320, 460);
//初始化映像視圖對象,大小是frame
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
//imageView的動畫圖片是數組images
imageView.animationImages = images;
//按照原始比例縮放圖片,保持縱橫比
imageView.contentMode = UIViewContentModeScaleAspectFit;
//切換動作的時間3秒,來控製圖像顯示的速度有多快,
imageView.animationDuration = 3;
//動畫的重複次數,想讓它無限迴圈就賦成0
imageView.animationRepeatCount = 0;
//開始動畫 www.2cto.com
[imageView startAnimating];
//添加控制項
[self.view addSubview:imageView];
//釋放記憶體
[imageView release];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidLoad
{
//定義數組,存放所有圖片對象
NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"xuanyi.jpg"],[UIImage imageNamed:@"xigua.jpg"],[UIImage imageNamed:@"juhua.jpg"],[UIImage imageNamed:@"heihua.jpg"],[UIImage imageNamed:@"cell.jpg"], nil];
//定義結構體,方塊大小
CGRect frame=CGRectMake(0, 0, 320, 460);
//初始化映像視圖對象,大小是frame
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
//imageView的動畫圖片是數組images
imageView.animationImages = images;
//按照原始比例縮放圖片,保持縱橫比
imageView.contentMode = UIViewContentModeScaleAspectFit;
//切換動作的時間3秒,來控製圖像顯示的速度有多快,
imageView.animationDuration = 3;
//動畫的重複次數,想讓它無限迴圈就賦成0
imageView.animationRepeatCount = 0;
//開始動畫
[imageView startAnimating];
//添加控制項
[self.view addSubview:imageView];
//釋放記憶體
[imageView release];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
ok,實現圖片切換!!
ok!實現!本部落格是我自己的練習,有好多地方沒有講太清楚,還請諒解!
摘自 任海麗(3G/移動開發)