iPhone 如何使用UIImageView播放動畫,並停留在之後一張圖片並添加播放結束時的事件

問題:如何使用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];

 

 當播放器播放完後,要執行的事件,可以添加如下代碼:

    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];
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章