ios - 为什么 UIImageView 延迟后才隐藏?

标签 ios cocoa uiimageview hidden quartz-graphics

点击 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 属性和参数使用常量 YESNO,而不是 true false

关于ios - 为什么 UIImageView 延迟后才隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16419697/

相关文章:

ios - 我正在显示诸如 Expendable Tableview 之类的数据

cocoa - 插入后 NSManagedObjectContextObjectsDidChangeNotification

ios - 如何使顶部图像不透明,以便背景图像不显示出来?

c++ - 单例实例化两次

c++ - 使用 Cocoa 和 C++ 时刷新屏幕上数据的正确方法是什么?

ios - 如何在 iOS Storyboard中将图像添加到 ImageView

ios - 拥有更大图像尺寸的风险是什么

ios - HealthKit 错误 : Error Domain=com. apple.healthkit Code=100 "Failed to open database"UserInfo= {NSLocalizedDescription=无法打开数据库}

ios - 如何在 13 英寸 Macbook Pro 上使用模拟器测试 iPad 视网膜应用程序?

ios - 在ios swift中实现地址搜索