iphone refresh images UIImageView

ぃ、小莉子 提交于 2019-12-04 19:51:11

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.

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];

then, you have a method:

- (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];
}

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

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

If you are looking for a way to refresh the UIImageView periodically, you can reference the following: http://www.shanison.com/2010/12/25/uiimageview-load-remote-image/

It sounds like you're probably loading the images off disk or network while playing a sound asynchronously. Perhaps you're using AudioServicesPlaySystemSound along with UIImage +imageWithContentsOfURL:? The actual image loading and sound playing code would be most useful here.

iosDev

This worked for me, when I wanted to change uiimageview background and refresh it, and continue executing code after that:

-(void)imgTapped_event:(UIImageView*)imgViewTapped
{
     imgViewTapped.backgroundColor=[UIColor whiteColor];

     //let the system update ui changes
     [NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.0f]];

     //continue your code execution, play sounds etc...

     //my helper method to play sound
     [self playSound:@"goodAnswer" sync:YES loops:0]; 
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!