Refreshing iOS view immediately

  • Code
  • iOS
  • objective-C
  • view

Archived from the original blog (2011). Links and product details may be out of date.

Invalidating a region on a window will cause the region to be redrawn on the next drawRect which will not occur immediately. To force the redraw immediately, set the image by using performSelectorOnMainThread and wait for call to return.

[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:UIGraphicsGetImageFromCurrentImageContext() waitUntilDone:YES];