So this is my first time I have to work with the IPad camera and I’ve got some problems with the UIImagePickerController, I can’t seem to lock it to portrait mode.
First I subclassed UIImagePickerController and implemented
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait);
}
but then I read it’s no use as UIImagePickerController shouldn’t be subclassed.
Next thing I tried was via the picker overlay, I created a class for it and implemented the same method. Still it doesn’t work, the method seems to be called exactly once each time I present the picker with the 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];
}
I just tried something else, locking the orientation of the presenting view controller, but the UIImagePickerController still rotates in all directions.
Another thing i noticed is that an orientation change also changes the settings of the UIImagePickerController. I have the camera set to front camera, when I take a picture with it, rotate the IPad and try to take another picture, the camera is set to rear camera. Very strange.
So what did I miss, any suggestions please on how I can lock the camera orientation? 🙂
Edit: Mixed up UIImagePickerController and UIPickerView, fixed 🙂
You can always roll your own camera implementation with AVFoundation.