强制UIView立即重绘,而不是在下一个运行循环期间重绘
我创建了一个UIImagePicker /摄像头视图,其中包含一个用于拍摄快照的工具栏和自定义按钮。我不能真正改变使用默认方式,因为自定义按钮,我正在绘制视图顶部。
I've created a UIImagePicker / camera view, with a toolbar and custom button for taking a snapshot. I can't really change to using the default way because of the custom button, and I'm drawing on top of the view.
当你按下按钮时,我想用UIGetScreenImage()拍摄截图;但是,即使我先隐藏它,工具栏也会显示在图像中:
When you hit the button, I want to take a screenshot using UIGetScreenImage(); however, the toolbar is showing up in the image, even if I hide it first:
//hide the toolbar
self.toolbar.hidden = YES;
// capture the screen pixels
CGImageRef screenCap = UIGetScreenImage();
我很确定这是因为即使隐藏了工具栏,它也会在函数重绘后重新绘制返回并进入下一个运行循环 - 调用UIGetScreenImage后。
I'm pretty sure this is because even though the toolbar is hidden, it gets redrawn once the function returns and we enter the next run loop - after UIGetScreenImage is called.
我尝试进行以下添加,但没有帮助:
I tried making the following addition, but it didn't help:
//hide the toolbar
self.toolbar.hidden = YES;
[self.toolbar drawRect:CGRectMake(0, 0, 320, 52)];
// capture the screen pixels
CGImageRef screenCap = UIGetScreenImage();
我也尝试使用setNeedsDisplay,但这也不起作用,因为再次抽奖发生在当前函数返回。
I also tried using setNeedsDisplay, but that doesn't work either because once again the draw happens after the current function returns.
有任何建议吗?谢谢!
尝试将UI元素隐藏在单独的选择器中,并使用 -performSelectorOnMainThread:withObject :waitUntilDone:
方法,使用 YES
获取 waitUntilDone
参数。然后使用另一个选择器进行屏幕捕获。
Try hiding the UI elements in a separate selector, and using the -performSelectorOnMainThread:withObject:waitUntilDone:
method, using YES
for the waitUntilDone
argument. Then follow that up with another selector for screen capture.