iPhone刷新图像UIImageView [英] iphone refresh images UIImageView

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

问题描述

我有一个很基本的问题.我有几张(5)UIImageView图片 我的屏幕.当我单击一个按钮时,我想更改每个图像 去别的东西.我还想随着每个图像的变化播放声音.

I have a rather basic question. I have several(5) UIImageView images on my screen. When I click a button, I want to change each image to something else. I also want to play a sound as each image is changed.

所以我基本上希望在每幅图像变化时发出喀哒声.

So I basically want a clicking sound as each image changes.

问题是,由于某种原因,如果我说5张图片,
声音先播放5次,然后图像改变.

The problem is, for some reason if I have say 5 images,
the sound gets played 5 times first and then the images change.

就像图像仅在控制权返回到 输入用户.

It's like the images only refresh when control goes back to the user for input.

一旦我告诉我要显示什么图像,我如何强迫"它刷新图像?

How can I "force" it to refresh the images as soon as i tell it what image to display?

我是iphone/macworld的新手,所以对我轻松一点:-)

I'm new to the iphone/macworld, so go easy on me :-)

里克

推荐答案

就像图像仅在控制权返回给用户输入时才刷新.

It's like the images only refresh when control goes back to the user for input.

这正是发生的情况.用户界面在主线程上进行了更新,因此在代码运行时不会进行任何更新.

That's exactly what happens. The UI is updated on the main thread so no updates happen whilst your code is running.

为了实现所需的功能,您将需要计时器.看一下NSTimer文档.您需要创建一个计时器,该计时器会触发一种方法来更改您的第二张图片,然后重新排队以更改您的第三张图片.有一种方便的方法可以创建所需的计时器:+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

In order to achieve what you want, you're going to need timers. Take a look at the NSTimer documentation. You need to create a timer that fires a method to change your second image and then requeue a timer to change your third image. There is a convenient method to create a timer like you need: + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

[NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(updateImage2:) userInfo:nil repeats:NO];

然后,您有一个方法:

- (void) updateImage2(NSTimer*)theTimer
{

     //Update image 2 here
     // play sound 2 here

    [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(updateImage3:) userInfo:nil repeats:NO];
}

我将留给您来实现方法updateImage3:;-)

I'll leave it to you to implement the method updateImage3: ;-)

以这种方式运行更新使主线程有机会更新UI.

Running the updates like this gives the main thread a chance to update the UI.

这篇关于iPhone刷新图像UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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