UIImage是定義一張圖片,而UIImageVIew是定義一個視圖,然後把圖片放進去
- (void)viewDidLoad { [super viewDidLoad]; // UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"] highlightedImage:[UIImage imageNamed:@"2"]]; UIImageView *imageV = [[UIImageView alloc] init]; imageV.frame = CGRectMake(100, 100, 150, 300); //設置是否允許用戶與控件交互 imageV.userInteractionEnabled = YES; //設置圖片渲染顏色 imageV.tintColor = [UIColor greenColor]; NSMutableArray *arrayM = [NSMutableArray array]; for (int i=0; i<40; i++) { NSString *name = [NSString stringWithFormat:@"eat_%02d", i]; UIImage *image = [UIImage imageNamed:name]; [arrayM addObject:image]; } //設置圖片動畫數組 imageV.animationImages = arrayM; //設置播放次數 imageV.animationRepeatCount = 1; //設置總播放時間 imageV.animationDuration = arrayM.count * 0.08; //開始播放動畫 [imageV startAnimating]; [self.view addSubview:imageV]; } - (void)startAnimating { NSLog(@"%s", __func__); } - (void)stopAnimating { NSLog(@"%s", __func__); } - (BOOL)isAnimating { NSLog(@"%s", __func__); return YES; }