简体   繁体   中英

iPhone: UIImagePickerController - standard zoom control doesn't work

I have a UIImagePickerController that is presented as a modal view controller. This works fine, except for when I try to add anything to the camera overlay view.

As soon as I modify the camera overlay view, the default zoom control stops working (although tap to focus still works). If I tap on the view, the zoom slider appears, but I am not able to slide it up and down like usual.

Here's the code I'm using:

        imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;     
        imagePickerController.allowsEditing = NO;
        imagePickerController.delegate = self;
        imagePickerController.showsCameraControls = YES;
        imagePickerController.wantsFullScreenLayout = NO;
        [imagePickerController.cameraOverlayView addSubview:overlayView];

        [self presentModalViewController:imagePickerController animated:YES];

Has anyone had a similar problem or can see what I'm doing wrong? I know it should work, as I've seen it on other apps that also use the default camera controls.

Thanks :)

After a lot of mucking round I've finally come across a solution. Don't use the cameraOverlayView property, instead add a subview to the UIImagePickerController with a frame of size CGRectZero.

In the following example, overlayView is a custom subclass of UIView which draws an image and passes touches through to the next responder:

OverlayView *overlayView = [[OverlayView alloc] initWithFrame:CGRectZero];

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;     
        imagePickerController.allowsEditing = NO;
        imagePickerController.delegate = self;
        imagePickerController.showsCameraControls = YES;
        [imagePickerController.view addSubview:overlayView];
        statViewController.imagePickerController = imagePickerController;
    }

-

And then, everything just works. Not sure if adding a subview to UIImagePickerController is documented and ok with Apple, but heaps of other apps use this (or a similar workaround) so shouldn't cause any submission problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM