Using cameraOverlayView with UIImagePickerController

前端 未结 3 1561
小鲜肉
小鲜肉 2020-12-31 13:58

I know this has been asked a number of time but I can\'t find an answer.

I have an app that uses the UIImagePickerController to take a picture. The prob

3条回答
  •  借酒劲吻你
    2020-12-31 14:46

    great information. To add a little to what Raghu did:

    up top:

    UIImagePicker *_imagePicker;
    
    //inside your take a picture method
    UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
    toolBar.barStyle =  UIBarStyleBlackOpaque;
    NSArray *items=[NSArray arrayWithObjects:
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel  target:self action:@selector(cancelPicker)],
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace  target:nil action:nil],
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera  target:self action:@selector(shootPicture)],
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace  target:nil action:nil],
                    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace  target:nil action:nil],
                    nil];
    [toolBar setItems:items];
    toolBar.backgroundColor=[UIColor blackColor];
    
    
    
    UIImageView *tp=[[UIImageView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width, 100)];
    
    tp.userInteractionEnabled=YES;
    tp.backgroundColor=[UIColor blackColor];
    
    [tp addSubview:toolBar]; //add the toolbar to the uiimageview
    
    _imagePicker=[[UIImagePickerController alloc]init];
    _imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
    _imagePicker.delegate = self;
    _imagePicker.showsCameraControls=NO;  //we will make custom controls.
    [_imagePicker.view addSubview:tp];
    
    
    
    -(void)cancelPicker{
    //get rid of the image picker
    [self dismissViewControllerAnimated:YES completion:nil]; //dismiss uiimagepicker
    _imagePicker=nil;
    }
    
    //take the picture, it will then go directly to - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info method
    -(void)shootPicture{
    [_imagePicker takePicture];
    }
    

提交回复
热议问题