在我的应用程序,我需要检测是否ImagePicker
准备拍照。我发现这里的解决方案:How to know if iPhone camera is ready to take picture?iOS NSNotificationCenter奇怪的延迟
所以我得到这个代码viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showButton:)
name:AVCaptureSessionDidStartRunningNotification object:nil];
和选择是这样的:
- (void)showButton:(NSNotification *)notification{
NSLog(@"---CAMERA READY");
[button setHidden:NO];
[button setAlpha:0.0];
[button setTransform:CGAffineTransformScale(CGAffineTransformIdentity, 1.5, 1.5)];
[UIView animateWithDuration:.2 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[button setAlpha:1.0];
[button setTransform:CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0)];
} completion:^(BOOL finished) {
}];
NSLog(@"---CAMERA READY");
}
这里是一些奇怪的事情发生,因为这两个NSLogs立即显示,但整个按钮动画甚至会在30秒后触发。
UIView是否单独更新?我如何同步日志和动画?
您可以检查是否收到AVCaptureSessionDidStartRunningNotification在后台线程?修改UI只能从主线程完成 – rist
我试过'dispatch_queue_t queue = dispatch_get_main_queue();'''dispatch_async',它现在可以工作,所以这是线程问题。 – cyborg86pl