2014-02-27 58 views
0

首先請原諒我也許小白的問題! 我的目標C全新!顯示在圖像動畫結束的最後一個圖像

我想動畫圖像,並在動畫結束時應顯示動畫「dymchart20.png」的最後一個圖像。 我怎樣才能做到這一點?

,這裏是我的動畫代碼:

aniChartView.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed:@"dymchart01.png"], 
           [UIImage imageNamed:@"dymchart02.png"], 
           [UIImage imageNamed:@"dymchart03.png"], 
           [UIImage imageNamed:@"dymchart04.png"], 
           [UIImage imageNamed:@"dymchart05.png"], 
           [UIImage imageNamed:@"dymchart06.png"], 
           [UIImage imageNamed:@"dymchart07.png"], 
           [UIImage imageNamed:@"dymchart08.png"], 
           [UIImage imageNamed:@"dymchart09.png"], 
           [UIImage imageNamed:@"dymchart10.png"], 
           [UIImage imageNamed:@"dymchart11.png"], 
           [UIImage imageNamed:@"dymchart12.png"], 
           [UIImage imageNamed:@"dymchart13.png"], 
           [UIImage imageNamed:@"dymchart14.png"], 
           [UIImage imageNamed:@"dymchart15.png"], 
           [UIImage imageNamed:@"dymchart16.png"], 
           [UIImage imageNamed:@"dymchart17.png"], 
           [UIImage imageNamed:@"dymchart18.png"], 
           [UIImage imageNamed:@"dymchart19.png"], 
           [UIImage imageNamed:@"dymchart20.png"],nil]; 

// all frames will execute in 3 seconds 
aniChartView.animationDuration = 0.8; 
// repeat the annimation forever 
aniChartView.animationRepeatCount = 1; 
// start animating 
[aniChartView startAnimating]; 

感謝您的幫助!

回答

0

您可以使用的NSTimer做,聲明你aniChartView因爲這樣你的類的屬性有用的解決方案:

@interface ViewController() 

@property (nonatomic, strong) UIImageView *aniChartView; 
@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void)beginAnimation { 
    self.aniChartView.animationImages = [NSArray arrayWithObjects: 
          [UIImage imageNamed:@"dymchart01.png"], 
          [UIImage imageNamed:@"dymchart02.png"], 
          [UIImage imageNamed:@"dymchart03.png"], 
          [UIImage imageNamed:@"dymchart04.png"], 
          [UIImage imageNamed:@"dymchart05.png"], 
          [UIImage imageNamed:@"dymchart06.png"], 
          [UIImage imageNamed:@"dymchart07.png"], 
          [UIImage imageNamed:@"dymchart08.png"], 
          [UIImage imageNamed:@"dymchart09.png"], 
          [UIImage imageNamed:@"dymchart10.png"], 
          [UIImage imageNamed:@"dymchart11.png"], 
          [UIImage imageNamed:@"dymchart12.png"], 
          [UIImage imageNamed:@"dymchart13.png"], 
          [UIImage imageNamed:@"dymchart14.png"], 
          [UIImage imageNamed:@"dymchart15.png"], 
          [UIImage imageNamed:@"dymchart16.png"], 
          [UIImage imageNamed:@"dymchart17.png"], 
          [UIImage imageNamed:@"dymchart18.png"], 
          [UIImage imageNamed:@"dymchart19.png"], 
          [UIImage imageNamed:@"dymchart20.png"],nil]; 

    // all frames will execute in 3 seconds 
    self.aniChartView.animationDuration = 0.8; 
    // repeat the annimation forever 
    self.aniChartView.animationRepeatCount = 1; 
    // start animating 
    [self.aniChartView startAnimating]; 

    [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(staticImage) userInfo:nil repeats:NO]; 

} 

-(void)staticImage { 

    [self.aniChartView stopAnimating]; 
    [self.aniChartView setImage:[UIImage imageNamed:@"dymchart20.png"]]; 

} 

@end 
+0

謝謝你這麼多SonGoku68 !我做到了,它就像一個魅力! –

0

動畫不改變他們的動畫元素的狀態。這意味着如果你的uiview有一個背景圖像,一旦動畫停止,這個圖像將是相同的。 同樣的事情也適用於彩色動畫變化,或與您的動畫任何其他財產。 爲了實現您的目標,一旦動畫結束,您必須顯式調用UIImage的更改爲您想要查看的那個。 :)

下面是你可能會發現https://stackoverflow.com/a/7773141/1306884