問題:如何使用UIImageView播放動畫,並停留在之后一張圖片
思路:
除了把動畫所需要的幾張圖片賦值給 animationImages 之外,多加一步 ,把最后一張圖片賦值給UIImageView的 Image就好了。
讓后就開始Animations。
代碼如下:
UIImageView *fishAni=[[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//
將指定的圖片載入 animationImages
fishAni.animationImages=[NSArray arrayWithObjects:
[UIImage imageNamed: @" 13.png "],
[UIImage imageNamed: @" 12.png "],
[UIImage imageNamed: @" 11.png "],
[UIImage imageNamed: @" 10.png "],nil ];
[fishAni setImage:[UIImage imageNamed: @" 10.png "]];
// 設定動畫的播放時間
fishAni.animationDuration= 1.0;
// 設定重復播放次數
fishAni.animationRepeatCount= 1;
// 開始播放動畫
[fishAni startAnimating];
[self.view addSubview:fishAni];
fishAni.animationImages=[NSArray arrayWithObjects:
[UIImage imageNamed: @" 13.png "],
[UIImage imageNamed: @" 12.png "],
[UIImage imageNamed: @" 11.png "],
[UIImage imageNamed: @" 10.png "],nil ];
[fishAni setImage:[UIImage imageNamed: @" 10.png "]];
// 設定動畫的播放時間
fishAni.animationDuration= 1.0;
// 設定重復播放次數
fishAni.animationRepeatCount= 1;
// 開始播放動畫
[fishAni startAnimating];
[self.view addSubview:fishAni];
當播放器播放完后,要執行的事件,可以添加如下代碼:
NSInteger AnimationNtimer =1;
NSTimer *animationTimer = [NSTimer scheduledTimerWithTimeInterval: AnimationNtimer target:self selector:@selector(ArrowAnimationPlay:) userInfo:nil repeats: NO];
播放結束后的事件。
-(void)ArrowAnimationPlay:(NSTimer *) timer{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"wtq" message:@"I have a message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}