【问题标题】:UIButton inside UIImagePickerController.cameraOverlayView not respondingUIImagePickerController.cameraOverlayView 内的 UIButton 没有响应
【发布时间】:2014-12-16 05:37:37
【问题描述】:

我在设置为 cameraOverlayView 的 UIView 中有一个 UIButton。

我还缩放了 uiimagepicker cameraView 以覆盖整个屏幕(如下图所示)。

这是我的代码:

 // CameraViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if(!self.imagePickerController)
        [self setupCamera];
}

-(void)setupCamera{
    self.imagePickerController = [[UIImagePickerController alloc] init];
    self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    self.imagePickerController.delegate = self;
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.imagePickerController.showsCameraControls = NO;

    self.imagePickerController.cameraOverlayView =  self.overlayView;

    [self scaleCameraPreview];

    // Present picker in the next loop (to avoid warning - "Presenting view controllers on detached view controllers is discouraged")
    [self performSelector:@selector(presentPicker) withObject:nil afterDelay:0.0];
}

-(void)presentPicker{
    [self presentViewController:self.imagePickerController animated:NO completion:nil];
}

-(void)scaleCameraPreview{
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;

    int heightOffset = 0;

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        heightOffset = 120;
    }

    float cameraAspectRatio = 4.0 / 3.0;
    float imageWidth = floorf(screenSize.width * cameraAspectRatio);
    float scale = ceilf(((screenSize.height + heightOffset) / imageWidth) * 10.0) / 10.0;
    self.imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
}

-(IBAction)cameraButtonPressed:(id)sender{
    [self.imagePickerController takePicture];
}

这是我的视图控制器层次结构:

- UINavigationController 
   - SWRevealViewController (manages a drawer functionality between different controllers)
     - UINavigationController (current controller for the camera)
       - CameraViewController 
         - PickerViewController (Presented modally as you can see above) 
           - PhotoTakenViewController (Controller that will fire after UIImagePicker returns an image)

编辑:添加叠加信息

我在网上搜索过类似的线程(例如UIImagePickerController Overlay Buttons Not Firing),但没有找到任何解决方案。

您在图片中看到的 UIButton 位于 UIView 内部,这是分配给 cameraOverlayView 的代码中的 overlayView。它还通过插座连接到cameraButtonPressed:动作,如果我不添加UIImagePickerController,它可以完美运行。

它不响应任何我不知道为什么的触摸。

有人知道发生了什么吗?

【问题讨论】:

  • 尝试在viewWillAppear中设置(setupCamera方法)
  • 已经试过了,没用@zala
  • @jonypz tr [self.view bringSubviewToFront:btn];
  • 没有工作 @Jageen ,并在加载图像选择器后做到了
  • @jonypz 自定义叠加的实现在哪里?

标签: ios uibutton uiimagepickercontroller overlay-view cameraoverlayview


【解决方案1】:

我已经解决了我的问题,但我相信粗略的方式:

[self presentViewController:self.imagePickerController animated:NO completion:^(void){

    // Re-add the button so it is on top of the overlay
    [self.imagePickerController.view addSubview:self.takePhotoButton];
}];

稍后可能会回到这个问题并发布更新,以防我找到更好的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 2021-04-01
    相关资源
    最近更新 更多