点击 UIView 后,我将其隐藏并使用 UIView 和 Quartz drawRect 初始化新对象。
- (void)viewTapped:(UITapGestureRecognizer *)recognizer {
self.vignetteView.hidden=true;
lupeItself = [[LoupeView alloc] initWithView:_pageView setZoomImageName:_zoomPageImageName setDelegate:self];
}
上面的代码仅在延迟约 2 秒后才隐藏 UImageView。但如果最后一行(LoupeView alloc 等)被删除,它会立即隐藏。为什么?如何让 View 瞬间隐藏?
最佳答案
在执行路径返回到主运行循环之前,.hidden = true
更改将不可见。第二行可能会阻塞几秒钟,以防止发生这些更改(或者 drawRect
在管道中花费了很长时间)。
最简单的解决方法是将第二行推迟到下一次运行循环迭代:
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];
}];
还有一个小问题:您应该为 BOOL
属性和参数使用常量 YES
和 NO
,而不是 true
和 false
。
关于ios - 为什么 UIImageView 延迟后才隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16419697/