NSTimer更改图像iPhone编程 [英] NSTimer change image iPhone Programming

查看:74
本文介绍了NSTimer更改图像iPhone编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iPhone程序中使用NSTimer定期更改图像?

How to change images periodically using NSTimer in iPhone progranmming?

我创建了一个用于加载图像的图像视图。

I create an image view for loading images.

我想在imageview中显示图像并使用NSTimer定期更改图像。

I want to display images in imageview and periodically change images by using NSTimer.

推荐答案

将您喜欢的图像导入到您的捆绑应用程序
将它们称为image1.png,image2.png image3.png等....

import the images you like to your bundle application called them image1.png, image2.png image3.png and so on....

在界面构建器中添加UIImageview调用它(引用) H文件中的theImage

Add UIImageview in interface builder call it (reference) "theImage"

@interface delme3ViewController : UIViewController {

    UIImageView *theImage;
    int imageCount;
}
@property (nonatomic, retain) IBOutlet UIImageView *theImage;

@end

- (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更改图像iPhone编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆