Why is UIImageView hiding only after a delay?

After listening to the UIView, I will hide it and initialize a new object using UIView and Quartz drawRect.

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

The code above hides the UImageView only after some delay of 2 seconds. But if the last line (LoupeView alloc, etc.) is deleted, it hides instantly. What for? How to make a view hide instantly?

+4
source share
1 answer

Changing .hidden = true will not become visible until the execution path returns to the main runloop. The second line is probably locked for a few seconds, preventing these changes from occurring (or drawRect takes a lot of time further down the pipeline).

The simplest solution would be to postpone the second line until the next iteration of runloop:

 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 small point: you should use the constants YES and NO for BOOL properties and arguments instead of true and false .

+7
source

Source: https://habr.com/ru/post/1479532/


All Articles