Ios creating simple camera overlay in Xcode how?

后端 未结 1 1563
醉梦人生
醉梦人生 2020-12-05 03:25

As the title says, I need to create a very simple camera overlay while taking photos with UIImagePickerController. I want to add very simple .png f

相关标签:
1条回答
  • 2020-12-05 04:03

    There is a property of UIImagePickerController called cameraOverlayView. It's an UIView*, so you need to create one and put your PNG to the background of it, then assign it to this property of your picker.

    Ok, here's the code (i didnt test it so)

    (IBAction) getPhoto:(id) sender 
    {
        UIImagePickerController * picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
    
        // creating overlayView
        UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.frame];
        // letting png transparency be
        overlayView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yourimagename.png"]];
        [overlayView.layer setOpaque:NO];
        overlayView.opaque = NO;
    
        picker.showsCameraControls = NO;
        picker.cameraOverlayView = overlayView;
    
        if((UIButton *) sender == choosePhotoBtn) 
        {
             if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
             {
                 [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
             } else {
                 //do something if the device has no camera or if the camera is disabled in settings (it cannot be assumed that the camera is available/not broken)
             }
        } else {
    
        }
    
        label1.text =@"PHOTO ACTION";
    
        [self presentModalViewController:picker animated:YES];
    }
    

    Of course, you can use some custom UIView* subclass instead of creating standard UIView* overlayView, but everything else will remain the same.

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