iOS:调用dismissModalViewController后,屏幕不再接收Touches

时间:2013-10-16 20:11:12

标签: ios uiimagepickercontroller modalviewcontroller

我有两个观点。非常简单的设置只是为了玩相机胶卷。

一个视图将使用以下方式调出相机胶卷:

[self presentViewController:self.imagePicker animated:NO completion:nil];    

UIButton触发。它带来了相机,一切都很好。

拍完照片后,我打电话给以下人员解雇控制器:

[self dismissViewControllerAnimated:NO completion:nil];

同样,一切正常。

但是,在模态视图被解除后,调出imagePicker控制器的视图不再接触(UIButton将不再重新启动相机)。

当我切换到另一个视图并返回时,它将再次开始接收触摸。

我一直在寻找这个问题的解决方案但是没有成功找到任何东西。提前谢谢。

编辑(添加代码):

在CameraController.m

这是启动相机胶卷的地方

(符合UIViewController的子类 <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

//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 arrayWithObjects:(NSString *) kUTTypeImage, nil];
        self.imagePicker.delegate = self;

    OverlayCameraView *cameraOverlay = [[OverlayCameraView alloc] initWithFrame:(CGRect){{0, 0}, 320, 480} andTheCameraController:self];
        self.imagePicker.cameraOverlayView = cameraOverlay;
   }
}

//Delegate Method when a picture is taken
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)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)initWithFrame:(CGRect)frame andTheCameraController:(CameraController*)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];
}

1 个答案:

答案 0 :(得分:1)

您应该通过dismissViewControllerAnimated方法在选择器self上调用UIImagePickerControllerDelegate

[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];