Unheilig
Unheilig

Reputation: 16302

iOS: Screen no longer receives Touches after calling dismissModalViewController

I have two views. Very simple set up just to play around with the camera roll.

One view will bring up the camera roll using:

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

which is triggered by a UIButton. It brings up the camera, everything's fine.

After taking a picture, I am calling the following to dismiss the controller:

[self dismissViewControllerAnimated:NO completion:nil];

Again, everything is working.

But the view that brings up the imagePicker Controller no longer receives touch (the UIButton will no longer brings up the camera again) after the Modal View is dismissed.

It will only start to receive touches again when I switch to another view and come back.

I have been searching for a solution to this problem but have not been successful in finding anything. Thanks in advance.

EDIT (Adding code):

In CameraController.m

This is where brings up the Camera Roll

(Subclass of UIViewController conforming to <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];  
}

In 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];
}

Upvotes: 2

Views: 197

Answers (1)

Joel
Joel

Reputation: 16134

You should be calling dismissViewControllerAnimated on the picker not self via the UIImagePickerControllerDelegate methods.

[picker dismissViewControllerAnimated:NO completion:nil];

or if you are keeping a reference to it:

[self.imagePicker dismissViewControllerAnimated:NO completion:nil];

EDIT:

Based on the revised code, I believe

self.imagePicker.cameraOverlayView = cameraOverlay;

should be:

self.imagePicker.cameraOverlayView = cameraOverlay.view;

Also this will cause a +2 reference count and will leak if you are not using ARC:

self.imagePicker = [[UIImagePickerController alloc] init];

It should be for proper reference counting:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
self.imagePicker = picker;
[picker release];

Upvotes: 1

Related Questions