我有两种观点。非常简单的设置只是为了玩相机胶卷。
一个 View 将使用以下方法调出相机胶卷:
[self presentViewController:self.imagePicker animated:NO completion:nil];
由 UIButton 触发。它打开了摄像头,一切都很好。
拍照后,我正在调用以下命令来关闭 Controller :
[self dismissViewControllerAnimated:NO completion:nil];
再次,一切正常。
但在模态视图关闭后,调出 imagePicker Controller 的 View 不再接收触摸(UIButton 将不再再次调出相机)。
只有当我切换到另一个 View 并返回时,它才会再次开始接收触摸。
我一直在寻找解决此问题的方法,但没有成功找到任何东西。提前致谢。
编辑(添加代码):
在 CameraController.m 中
这是调出相机胶卷的地方
(UIViewController 的子类符合
)
//UIButton that brings up the imagePicker
- (IBAction)useCamera
{
[self prepareImagePicker];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
//Initializing ImagePicker
- (void)prepareImagePicker
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.mediaTypes = [NSArray arrayWithObjectsNSString *) kUTTypeImage, nil];
self.imagePicker.delegate = self;
OverlayCameraView *cameraOverlay = [[OverlayCameraView alloc] initWithFrameCGRect){{0, 0}, 320, 480} andTheCameraController:self];
self.imagePicker.cameraOverlayView = cameraOverlay;
}
}
//Delegate Method when a picture is taken
-(void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info
{
self.imagePicker.delegate = nil;
[picker dismissViewControllerAnimated:NO completion:nil];
self.imagePicker = nil;
self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
在 OverlayCameraView.m
//Camera Overlay Class (Subclass of UIView)
- (id)initWithFrameCGRect)frame andTheCameraControllerCameraController*)cameraController
{
if ((self = [super initWithFrame:frame]))
{
self.camera = cameraController;
//.…2 UIButtons set up
}
return self;
}
//Overlay Cancel Button
- (void) cancel
{
[self.camera dismissViewControllerAnimated:NO completion:nil];
}
//Overlay Take Picture Button
- (void) takeAPicture
{
[self.camera.imagePicker takePicture];
}
Best Answer-推荐答案 strong>
您应该通过 UIImagePickerControllerDelegate 方法在选择器上调用 dismissViewControllerAnimated 而不是 self 。
[picker dismissViewControllerAnimated:NO completion:nil];
或者如果您保留对它的引用:
[self.imagePicker dismissViewControllerAnimated:NO completion:nil];
编辑:
根据修改后的代码,我相信
self.imagePicker.cameraOverlayView = cameraOverlay;
应该是:
self.imagePicker.cameraOverlayView = cameraOverlay.view;
如果您不使用 ARC,这也会导致 +2 引用计数并且会泄漏:
self.imagePicker = [[UIImagePickerController alloc] init];
应该是为了正确的引用计数:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
self.imagePicker = picker;
[picker release];
关于iOS:调用dismissModalViewController后屏幕不再接收触摸,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/19412878/
|