UIImagePickerController startVideoCapture with custom overlay

后端 未结 2 1127
花落未央
花落未央 2021-01-13 14:58

I am using UIImagePickerController with a custom overlay to record a video in my app. For the implementation of the UIImagePickerController, I have used the code from a grea

相关标签:
2条回答
  • 2021-01-13 15:05

    The problem is that the action you attach to the initWithBarButtonSystemItem call doesn't pass the UIImagePickerController instance along.

    What I would do is set the UIImagePickerController as a property of your class and access that property from your action, like this:

    In your .h:

    @property (nonatomic, strong) UIImagePickerController *cameraUI;
    

    In your .m:

    - (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
                               usingDelegate: (id <UIImagePickerControllerDelegate,
                                               UINavigationControllerDelegate>) delegate {
    
        ...
    
        self.cameraUI = [[UIImagePickerController alloc] init];
    
        ...
    
        UIBarButtonItem *RecordBarButtonItem = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(recordPressed)]; // Removed the ':'
    
        ...
    }
    
    
    - (void) recordPressed {
        NSLog(@"lets record");
        [self.cameraUI startVideoCapture]; 
    }
    
    0 讨论(0)
  • 2021-01-13 15:22

    Actually I've just quickly tested it in some code I've gotten open, the sender for your action on the button press is UIBarButtonItem *. So there's a couple of things you can do, you can either go down the root of

    UIBarButtonItem *senderButton = (UIBarButtonItem *)sender; 
    if(senderButton.image == UIBarButtonSystemItemCamera)
    {
       //Handle behaviour
    }
    

    Or set the tag variable for each button and skip the image check and look at the tags instead, which might make the logic a bit easier.

    0 讨论(0)
提交回复
热议问题