本文實例為年夜家分享了IOS應用UIImageView控件制造動畫的辦法,供年夜家參考,詳細內容以下
先添加40張tomcat的圖片到資本列表中:稱號為cat_eat0000.jpg到cat_eat0039.jpg。
1、界說所需控件
// 界說按鈕,圖片控件、可變數組對象 UIButton *actionbuttom; UIImageView *imageMove; NSMutableArray *imgsarray;
2、初始化各控件
// image動畫
// 初始化UIImageView,年夜小和View的年夜小雷同
imageMove = [[UIImageView alloc]initWithFrame:self.view.frame];
// 設置UIImageView的初始化圖片
imageMove.image = [UIImage imageNamed:@"cat_eat0000.jpg"];
// 把UIImageView加載到頁面
[self.view addSubview:imageMove];
// 設置UIImageView的交互性為yes
imageMove.userInteractionEnabled = YES;
// 創立功效按鈕
// 初始化按鈕
actionbuttom = [[UIButton alloc]initWithFrame:CGRectMake(100, 680, 218, 50)];
// 設置按鈕配景色
actionbuttom.backgroundColor = [UIColor yellowColor];
// 設置按鈕題目
[actionbuttom setTitle:@"開端播放" forState:UIControlStateNormal];
// 設置按鈕文字色彩
[actionbuttom setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// 為按鈕添加觸發事宜
[actionbuttom addTarget:self action:@selector(startmove:) forControlEvents:UIControlEventTouchUpInside];
// 把按鈕添加到頁面中
[imageMove addSubview:actionbuttom];
// 初始化可變數組,用來寄存圖片
imgsarray = [[NSMutableArray alloc]initWithCapacity:40];
// 輪回從資本中拿到四十張圖片,並添加到imgsarray。
for (int x=0; x<40; x++) {
NSString *imgname = [NSString stringWithFormat:@"cat_eat00%.2d.jpg",x];
UIImage *img = [UIImage imageNamed:imgname];
[imgsarray addObject:img];
3、設置按鈕觸動員畫播放
//按鈕的觸發事宜
-(void)startmove:(id)sender{
// 設置動畫時長
imageMove.animationDuration = 2;
// 設置動繪圖片起源為圖片數組
imageMove.animationImages = imgsarray;
// 設置動畫反復次數,0是無窮輪回,1為反復1次
imageMove.animationRepeatCount = 1;
// 開端播放
[imageMove startAnimating];
}
以上就是本文的全體內容,願望對年夜家進修應用UIImageView控件制造動畫有所贊助。
【IOS UI進修教程之應用UIImageView控件制造動畫】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!