2011-08-27 49 views
0

我試圖解決幾個星期的問題,但我找不到答案。 我試圖讓動畫結束時最後一幀凍結。凍結xcode圖像動畫的最後一幀

這是我的動畫代碼:

-(IBAction)play { 
    image.animationImages = [NSArray arrayWithObjects: 
                             [UIImage imageNamed:@"1.png"], 
                             [UIImage imageNamed:@"2.png"],  
                             [UIImage imageNamed:@"3.png"],  
                             [UIImage imageNamed:@"4.png"],  
                             [UIImage imageNamed:@"5.png"],  
                             [UIImage imageNamed:@"6.png"],  
                             [UIImage imageNamed:@"7.png"],  
                             [UIImage imageNamed:@"8.png"],  
                             [UIImage imageNamed:@"9.png"],  
                             [UIImage imageNamed:@"10.png"],  
                             [UIImage imageNamed:@"11.png"],  
                             [UIImage imageNamed:@"12.png"],  
                             [UIImage imageNamed:@"13.png"],nil]; 
     
    [image setAnimationRepeatCount: 1]; 
    image.animationDuration = 0.5; 
     
    [image startAnimating]; 

     
} 

-(IBAction)stop{ 
   [image stopAnimating]; 
} 

當我按下按鈕播放,動畫運行,當我按下按鈕停止時,停止動畫和disapear圖像。

我喜歡做這個事情沒有停止按鈕,當動畫結束時,最後一幀是可見的。

謝謝你的幫助。

回答

0

我不知道這是否是最簡單的方法,但它的工作原理。在這裏,您有:

- (IBAction)stop { 
    CGSize screenSize = [[UIScreen mainScreen] applicationFrame].size; 
    CGContextRef context = CGBitmapContextCreate(nil, screenSize.width, screenSize.height, 8, 4 * (int)screenSize.width, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast); 

    CGBitmapContextCreateImage(context); 
    CGContextTranslateCTM(context, 0.0, screenSize.height); 
    CGContextScaleCTM(context, 1.0, -1.0); 

    [(CALayer*)self.layer renderInContext:context]; 

    CGImageRef cgImage = CGBitmapContextCreateImage(context); 
    UIImage *lastFrame = [[UIImage alloc] initWithCGImage:cgImage]; 
    CGImageRelease(cgImage); 
    CGContextRelease(context); 

    image.image = lastFrame; 
    [lastFrame release]; 
} 
+0

感謝我會盡力。 – nioan7

0

如果你只是做:

-(IBAction)stop { 
    [image stopAnimating]; 
    image.image = [image.animationImages objectAtIndex:12]; //or 0 to jump to the first image 
} 

爲我工作:)