所以这是我第一次使用IPad相机并且UIImagePickerController遇到了一些问题,我似乎无法将其锁定为纵向模式。
首先我将UIImagePickerController子类化并实现了
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait);
}
然后我读了它没用,因为UIImagePickerController不应该是子类。
我尝试的下一件事是通过picker overlay,我为它创建了一个类并实现了相同的方法。它仍然不起作用,每次我使用叠加层呈现选择器时,该方法似乎只被调用一次。
- (void)viewDidLoad{
[super viewDidLoad];
_imagePicker = [[UIImagePickerController alloc] init];
[_imagePicker setDelegate:self];
[_imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[_imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
[_imagePicker setCameraCaptureMode:UIImagePickerControllerCameraCaptureModePhoto];
[_imagePicker setAllowsEditing:YES];
[_imagePicker setShowsCameraControls:YES];
[_imagePicker setNavigationBarHidden:YES];
[_imagePicker setToolbarHidden:YES];
[_imagePicker setWantsFullScreenLayout:YES];
CameraOverlay *_overlay = [[CameraOverlay alloc] init];
[_overlay set_imagePicker:_imagePicker];
[_imagePicker setCameraOverlayView:_overlay.view];
}
-(IBAction)takePicture:(id)sender {
[self presentModalViewController:_imagePicker animated:YES];
}
我只是尝试了其他方法,锁定了呈现视图控制器的方向,但UIImagePickerController仍然在所有方向上旋转。 我注意到的另一件事是方向更改也会更改UIImagePickerController的设置。我将相机设置为前置摄像头,当我用它拍照时,旋转IPad并尝试拍摄另一张照片,相机设置为后置摄像头。很奇怪。
那么我想念的是什么,请问我如何锁定相机方向? :)
编辑:混合UIImagePickerController和UIPickerView,修复:)