分配cameraOverlyView属性时,UIImagePickerController didFinishPickingMediaWithInfo未被调用

时间:2015-06-18 15:10:25

标签: ios objective-c uiimagepickercontroller

我设置UIImagePickerController模式视图来录制视频,一旦用户选择"使用视频"它可以很好地解除视图控制器的问题,完全符合我的要求。但是,只要我添加一个cameraOverlayView,它只是一个没有任何特殊功能的UIView,就永远不会调用didFinishPickingMediaWithInfo。即使我在该功能的第一行放置了NSLog,我也看不到任何输出。更奇怪的是,当用户按下“取消”按钮时,仍会调用UIImagePickerControllerDidCancel

关于SO的先前建议似乎没有用,因为我设置了委托并相应地设置了编辑属性,这与这些热门帖子不同:

  • uiimagepickercontroller didfinishpickingmediawithinfo NOT CALLED when selecting a video from the library
  • UIImagePickerController didFinishPickingMediaWithInfo not being called
  • 这里是启动UIImagePickerController的代码(取自Ray Wenderlich教程):

    -(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
                                     usingDelegate:(id )delegate {
    
        if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
            || (delegate == nil)
            || (controller == nil)) {
            return NO;
        }
    
         if(![delegate conformsToProtocol:@protocol(UIImagePickerControllerDelegate) ]) {        
            NSAssert(nil, @"delegate muste conforms to UIImagePickerControllerDelegate protocol");
        }else{
             NSLog(@"delegate does conform to protocol");
         }  
    
        CGRect screenRect = [[UIScreen mainScreen]bounds];
        CGFloat screenWidth = screenRect.size.width;
        CGFloat screenHeight = screenRect.size.height;
        CameraOverlay *overlay = [[CameraOverlay alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
        UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
        cameraUI.delegate = delegate;
        cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
        cameraUI.allowsEditing = NO;
        //if I comment out the line below, everything works fine.
        //but if I don't comment this out, didFinishPickingMediaWithInfo is never called
        cameraUI.cameraOverlayView = overlay;
        [controller presentModalViewController: cameraUI animated: YES];
        return YES;
    }
    

    这是didFinishPickingMediaWithInfo

    的一部分
    (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
        NSLog(@"did finish picking media with info");
    
        NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
        [self dismissModalViewControllerAnimated:NO];
        // I also tried [picker dismissModalViewControllerAnimated:NO];
        //despite it not being its own delegate, but in any case
        //this did not change the result
    
    ...
    }
    

    我按照Andrey的建议添加了有效的委托检查,但现在我总是看到"委托确实符合协议"无论叠加层是否在,并且didFinishPickingMediaWithInfo被调用。

    有关代码尝试或错误的建议吗?谢谢你看看。

    2 个答案:

    答案 0 :(得分:1)

    以下是最终有用的内容:为覆盖视图设置userInteractionEnabledFALSE

    我希望我知道这是一个错误还是一个功能。我查看了几个用于创建叠加视图的教程,没有提到设置此属性。如果有人能够完全解释为什么这会带来不同,我想标记一个比这更完整的答案。

    答案 1 :(得分:0)

    @sunny终于正确解决了! userInteractionEnabled = FALSE调用didFinishPickingMediaWithInfo