xcode iPhone:UIImagePickerController - 标准缩放控制不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5288908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:28:36  来源:igfitidea点击:

iPhone: UIImagePickerController - standard zoom control doesn't work

iphoneobjective-cxcodeuiimagepickercontroller

提问by Jordan Smith

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.

我有一个 UIImagePickerController,它显示为一个模态视图控制器。这很好用,除非我尝试向相机叠加视图添加任何内容。

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 :)

谢谢 :)

采纳答案by Jordan Smith

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.

经过一番折腾,我终于找到了一个解决方案。不要使用 cameraOverlayView 属性,而是将一个子视图添加到 UIImagePickerController 中,框架大小为 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 是 UIView 的自定义子类,它绘制图像并将触摸传递给下一个响应者:

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.

然后,一切正常。不确定将子视图添加到 UIImagePickerController 是否记录在案并且与 Apple 一起使用,但其他应用程序的大量使用此(或类似的解决方法),因此不应导致任何提交问题。