I have used ImagePickerController and should be familiar with this Code:
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
ImagePicker. delegate = self;
ImagePicker. sourceType = sourceType;
If (popover ){
[Popover release];
}
Popover = [[UIPopoverController alloc] initWithContentViewController: imagePicker];
ImagePicker. wantsFullScreenLayout = YES;
[Popover presentpoverfromrect: CGRectMake (vwPopover. frame. origin. x, vwpopopover. frame. origin. y, vwPopover. size. width, 0)
InView: self. view
PermittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES];
[ImagePickerrelease];
To be fair, there are countless bugs in the ImagePickerController provided by the SDK, which is far from easy to use. You cannot set its frame, full screen, custom its interface, or take photos continuously (only one photo can be taken at a time.
However, I recently encountered a new Bug. I have an iPad app that only supports portrait mode (vertical). When the app uses PopOverController to present the ImagePickerController photo interface, the camera lens is rotated 90 degrees by the clockwise side.
But when I turn off the screen (I'm sure I need to turn off the screen), I rotate the screen to the horizontal screen, and the ImagePickerController is displayed again, but the camera lens is normal.
No similar bug reports were found on the Internet. It seems to be only an example. Unfortunately, I have encountered it.
View the apple documentation, which says ImagePickerController only supports portrait screens and does not support landscape screens.
The problem is that my application only supports portrait screens? From two images, ImagePickerController clearly misjudges the device direction. It recognizes the status of the portrait screen as a landscape screen and the status of the landscape screen as a portrait screen, this makes me fail to figure out what the truth is.
The solution is to check the device direction before the ImagePickerController pops up. When the device is identified as a horizontal screen (the real direction is a portrait screen at this time. Alas, let's make a mistake.) rotate ImagePickerController 90 degrees clockwise:
If (sourceType = UIImagePickerControllerSourceTypeCamera
& (UIDeviceOrientationIsLandscape ([[UIDevice currentDevice] orientation]) {
ImagePicker. cameraViewTransform = CGAffineTransformMakeRotation (M_PI/2 );
}
[Popover presentpoverfromrect: CGRectMake (vwPopover. frame. origin. x, vwpopopover. frame. origin. y, vwPopover. size. width, 0)
InView: self. view
PermittedArrowDirections ctions: UIPopoverArrowDirectionAny animated: YES];
This is finally solved.
From kmyhy's column