How Do I Force a View to Redraw Itself Several Times Within a Method?
I have a UIImageView whose image I want to change depending on user input. For example, the user clicks a button, after which the background image is swapped out for another image开发者_开发问答. The program blocks for a second or two, and then the new image is swapped out for the original image. The problem is, it seems that the view doesn't redraw itself until the method has returned, so that the middle UIImage is never displayed.
How can I override this behavior to get the UIImageView (or the view itself) to redraw itself in the middle of a method?
When user click, start a NSTimer :
- (IBAction)btnTouched:(id)sender
{
[NSTimer scheduledTimerWithTimeInterval:_YOUR_TIME_
target:self
selector:@selector(timerFinished:)
userInfo:nil
repeats:NO];
}
- (void)timerFinished:(NSTimer *)timer
{
// Change your image
}
It should not block your program.
精彩评论