我有一個UIImagePickerController
自定義覆蓋。我試圖實現取消按鈕,將彈出UIImagePickerController
。我的代碼設置如下:無法彈出UIImagePickerController
- (void)tapPhoto {
//setup the picker
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;
self.picker.showsCameraControls=NO;
self.cameraOverlay = [[CameraOverlay alloc] init];
UIImage *camoverlayImage = self.cameraOverlay.cameraOverlayImage;
UIImageView *camoverlayImageView = [[UIImageView alloc] initWithImage:camoverlayImage];
camoverlayImageView.frame=CGRectMake(0, 0, self.cameraOverlay.previewSize.width , self.cameraOverlay.previewSize.height);
//init the control view
UIView *cameraControls= [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
[cameraControls addSubview:camoverlayImageView];
//Shutter Button
UIButton *button = [[UIButton alloc] init];//70*70
[button setBackgroundImage:[UIImage imageNamed:@"cameraoff"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"cameraon"] forState:UIControlStateHighlighted];
button.frame = CGRectMake(([[UIScreen mainScreen] bounds].size.width/2)-70/2, [[UIScreen mainScreen] bounds].size.height-70-10, 70 , 70);
[button addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];
[cameraControls addSubview:button];
UIButton *button2 = [[UIButton alloc] init];
[button2 setTitle:@"Cancel" forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(cancelPhoto) forControlEvents:UIControlEventTouchUpInside];
button2.frame = CGRectMake(5, [[UIScreen mainScreen]bounds].size.height-30, 0, 0);
[button2 sizeToFit];
[cameraControls addSubview:button2];
[self.picker setCameraOverlayView:cameraControls];
[self presentViewController:self.picker animated:YES completion:NULL];
}
-(void)cancelPhoto{
NSLog(@"photo canceled");
[self.navigationController pushViewController:self.picker animated:YES];
}
-(void)takePhoto{
//this will auto trigger the control
[self.picker takePicture];
}
我想從導航控制器彈出它,但沒有任何運氣。我也試過[self.picker popViewControllerAnimated:YES];
。任何人都可以給我任何指示爲什麼這不起作用?由於