Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why UIImageView hides only after delay?

After a UIView is tapped, I hide it and initialize new object with UIView and Quartz drawRect.

- (void)viewTapped:(UITapGestureRecognizer *)recognizer {   
    self.vignetteView.hidden=true;
    lupeItself = [[LoupeView alloc] initWithView:_pageView setZoomImageName:_zoomPageImageName setDelegate:self];
} 

Code above is hiding the UImageView only after some 2 seconds delay. But if last line (LoupeView alloc etc.) is removed, the it is hided instantly. Why? How to make the view hide instantly?

like image 391
Janis Jakaitis Avatar asked Mar 24 '23 01:03

Janis Jakaitis


1 Answers

The .hidden = true change will not become visible until the execution path returns to the main runloop. The second line is probably blocking for a few seconds, preventing these changes from occuring (or drawRect is taking a long time further down the pipeline).

The simplest fix would be to defer the second line until the next runloop iteration:

self.vignetteView.hidden = YES;
// defer execution so the above changes are immediately visible
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    lupeItself = [[LoupeView alloc] initWithView:_pageView setZoomImageName:_zoomPageImageName setDelegate:self];
}];

Also, a minor point: you should use the constants YES and NO for BOOL properties and arguments, instead of true and false.

like image 131
Mike Weller Avatar answered Apr 01 '23 00:04

Mike Weller