I am trying to rotate a UIImage
while capturing an image using the camera. However, I am getting the preview in portrait
mode only. How do I display the preview image in landscape
mode?
Reading the documentation for UIImagePickerController
reveals this interesting tidbit:
The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing.
Despite Apple's warning, there is one way of doing things:
You can subscribe to rotation notifications in a delegate class:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Then, based on the current rotation of the device, you can apply a CGAffineTransform
to your overlay view. An example of this kind of transform can be found here . That particular answer will not help you in iOS 6, because the shouldAutorotateToInterfaceOrientation
calls will never be made to your UIViewController
subclass. Your best version strategy will be to subscribe to the notifications. Keep in mind that you're going full manual here and your best bet is to figure out a way to only support portrait mode.
Also, make sure to balance the notification calls with this call when finished:
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.