objective-c – UIImagePickerController的快门
发布时间:2020-12-16 06:58:40 所属栏目:百科 来源:网络整理
导读:我有UI ImagePickerController的错误,其源类型是相机.有时控制器出现后,快门没有打开,我无法看到相机视频信号,但拍摄的照片是正确的. 可能是我做错了什么?码: if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCame
我有UI
ImagePickerController的错误,其源类型是相机.有时控制器出现后,快门没有打开,我无法看到相机视频信号,但拍摄的照片是正确的.
可能是我做错了什么?码: if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){ UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init]; cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera; cameraUI.allowsEditing = NO; cameraUI.showsCameraControls = NO; cameraUI.delegate = self; NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil]; UIView *controlsView = [nibObjects objectAtIndex:0]; CGRect overlayViewFrame = cameraUI.cameraOverlayView.frame; CGRect controlsFrame = CGRectMake(0.0,CGRectGetHeight(overlayViewFrame) - 54.0,CGRectGetWidth(overlayViewFrame),54.0); controlsView.frame = controlsFrame; [cameraUI.cameraOverlayView addSubview:controlsView]; [self presentModalViewController: cameraUI animated: YES]; } 解决方法
在锁定/解锁应用程序后,我发生了同样的情况,看起来快门在viewDidAppear上打开.
所以,我将我的父视图控制器订阅到UIApplicationDidBecomeActiveNotification并手动重新执行包含UIImagePickerController的控制器的viewWillAppear和viewDidAppear方法 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; . . . - (void)applicationBecomeActive { if (imagePicker_) [imagePicker_ openShutter]; } 然后在包含UIImagePickerController的控制器上 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [imagePickerController_ viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [imagePickerController_ viewDidAppear:animated]; imagePickerController_.cameraFlashMode = cameraFlashMode_; imagePickerController_.cameraDevice = cameraDevice_; } - (void)openShutter { [imagePickerController_ viewWillAppear:YES]; [imagePickerController_ viewDidAppear:YES]; } PS:如果你试试这个,不要忘记删除观察者 [[NSNotificationCenter defaultCenter] removeObserver:self]; 希望这可以帮助 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读