- (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. }