如何在iPhone编程中使用NSTimer定期更改图像?NSTimer change image iPhone编程
我为图像加载创建图像视图。
我想要在imageview中显示图像,并通过使用NSTimer定期更改图像。
如何在iPhone编程中使用NSTimer定期更改图像?NSTimer change image iPhone编程
我为图像加载创建图像视图。
我想要在imageview中显示图像,并通过使用NSTimer定期更改图像。
导入你喜欢的图片到你的应用程序捆绑叫 他们image1.png,image2.png image3.png等等....
Interface Builder中添加的UIImageView调用它(参考) “theImage”
在H文件:
@interface delme3ViewController : UIViewController {
UIImageView *theImage;
int imageCount;
}
@property (nonatomic, retain) IBOutlet UIImageView *theImage;
@end
在M档:
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(animateFunction)
userInfo:nil
repeats:YES];
imageCount = 1;
}
-(void)animateFunction
{
NSLog(@"Timer heartbeat %i",imageCount);
imageCount = imageCount + 1;
NSString *imageName = [NSString stringWithFormat:@"image%i.png"];
[theImage setImage:[UIImage imageNamed:imageName]];
}
您还可以使用图像名称数组而不是重命名包中的图像。 :)
而不是使用NSTimer,我只会使用UIImages的arrary和动画他们。请参阅文档from here。
该方法的结果是使用许多大型图像更平滑的动画。 – ozz
我将如何使用此淡入淡出图像?使时间间隔更长一点,而且哪个方法会调用fadeinandout/alpha更改为uiimageview? – jsetting32
链接已死... – Chris
或者可以使用一个UIImage对象数组。 (尽管由于系统缓存图像的方式,这通常不会带来任何好处。) –