簡體   English   中英

逐幀動畫UIImageView

[英]Animating UIImageView frame by frame

我有一個關於如何使用逐幀方法添加動畫UIImageView的想法,但我的問題是關於如何對UIImageView進行動畫處理,該方法已經作為IBOutlet UIImageView添加到了視圖控制器故事板上。

在這種和平的代碼中將發生什么變化?

NSArray *myImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"bookmark1.png"],
                         [UIImage imageNamed:@"bookmark2.png"],
                         [UIImage imageNamed:@"bookmark3.png"],
                         [UIImage imageNamed:@"bookmark4.png"],
                         [UIImage imageNamed:@"bookmark5.png"],nil];

    myAnimatedView = [UIImageView alloc];

   [myAnimatedView initWithFrame:CGRectMake(0, 0, 131, 125)];

    myAnimatedView.animationImages = myImages;

    myAnimatedView.animationDuration = 0.25;

    myAnimatedView.animationRepeatCount = 1;

    [myAnimatedView startAnimating];

    [self.navigationController.view addSubview:myAnimatedView];

我想在我的viewController上為該圖像設置動畫

http://imageshack.us/a/img717/3051/bookmarkl.gif

更容易了。 首先,添加.h文件:

@property (nonatomic, retain) IBOutlet UIImageView *iV;

之后,將此插座連接到情節提要上的實際UIImageView。 更改您的代碼:

iV.animationImages = myImages;
iV.animationDuration = 0.25;
iV.animationRepeatCount = 1;
[iV startAnimating];

就這樣。 希望這有所幫助

ps是的,不要忘記iV = nil; in-(void)viewDidUnload方法

UPD:已添加

[self performSelector:@selector(animationDone) withObject:nil afterDelay:0.25];

在startAnimating調用之后,顯然添加了animationDone方法:

- (void)animationDone {
    [iV stopAnimating];
    [iV setImage:[UIImage imageNamed:@"bookmark5.png"]];
}

好吧,幾乎一樣。 您不需要分配圖像視圖[[UIImageView alloc] init]也不需要將其添加到viewController。 其余部分相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM