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

时间:2011-03-13 10:51:28

标签: iphone objective-c xcode uiimagepickercontroller

我有一个UIImagePickerController,它是一个模态视图控制器。这种方法很好,除了我尝试向相机叠加视图添加任何内容时。

一旦我修改了相机覆盖视图,默认的缩放控制就会停止工作(尽管点击仍然有效)。如果我点击视图,会出现缩放滑块,但我无法像往常一样上下滑动。

这是我正在使用的代码:

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

有没有人有过类似的问题或者能看出我做错了什么?我知道它应该可以工作,因为我在其他也使用默认相机控件的应用程序上看到了它。

谢谢:)

1 个答案:

答案 0 :(得分:0)

经过大量的捣乱后,我终于遇到了一个解决方案。不要使用cameraOverlayView属性,而是使用大小为CGRectZero的帧向UIImagePickerController添加子视图。

在下面的示例中,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;
    }

-

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