0
我想使用NSTimer將UIImage數組添加到UIImageView。這樣它就會像動畫一樣。如何在iOS中做到這一點? 在此先感謝。如何使用NSTimer添加像動畫的UIImages?
我想使用NSTimer將UIImage數組添加到UIImageView。這樣它就會像動畫一樣。如何在iOS中做到這一點? 在此先感謝。如何使用NSTimer添加像動畫的UIImages?
有一個非常簡單的方法來做到這一點。
// create the view that will execute our animation
UIImageView* campFireView = [[UIImageView alloc] initWithFrame:self.view.frame];
// load all the frames of our animation
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"campFire01.gif"],
[UIImage imageNamed:@"campFire02.gif"],
[UIImage imageNamed:@"campFire03.gif"],
[UIImage imageNamed:@"campFire04.gif"],
[UIImage imageNamed:@"campFire05.gif"],
[UIImage imageNamed:@"campFire06.gif"],
[UIImage imageNamed:@"campFire07.gif"],
[UIImage imageNamed:@"campFire08.gif"],
[UIImage imageNamed:@"campFire09.gif"],
[UIImage imageNamed:@"campFire10.gif"],
[UIImage imageNamed:@"campFire11.gif"],
[UIImage imageNamed:@"campFire12.gif"],
[UIImage imageNamed:@"campFire13.gif"],
[UIImage imageNamed:@"campFire14.gif"],
[UIImage imageNamed:@"campFire15.gif"],
[UIImage imageNamed:@"campFire16.gif"],
[UIImage imageNamed:@"campFire17.gif"], nil];
// all frames will execute in 1.75 seconds
campFireView.animationDuration = 1.75;
// repeat the annimation forever
campFireView.animationRepeatCount = 0;
// start animating
[campFireView startAnimating];
// add the animation view to the main window
[self.view addSubview:campFireView];
來源:http://web.archive.org/web/20120305060003/http://appsamuck.com/day2.html
該鏈接都到了404頁,是*正是*爲什麼鏈接只答案是一個壞主意! –
對不起。我現在更新了代碼。 – imthi