简体   繁体   English

如何在iPhone中旋转相机预览模式

[英]how to rotate camera preview mode in iphone

I am trying to rotate a UIImage while capturing an image using the camera. 我正在尝试使用相机捕获图像时旋转UIImage However, I am getting the preview in portrait mode only. 但是,我只能在portrait模式下预览。 How do I display the preview image in landscape mode? 如何在landscape模式下显示预览图像?

Reading the documentation for UIImagePickerController reveals this interesting tidbit: 阅读 UIImagePickerController 的文档将揭示这个有趣的花絮:

The UIImagePickerController class supports portrait mode only. UIImagePickerController类仅支持纵向模式。 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. 然后,根据设备当前的旋转角度,可以将CGAffineTransform应用于叠加视图。 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. 在iOS 6中,该特定答案将无济于事,因为对UIViewController子类将永远不会进行shouldAutorotateToInterfaceOrientation调用。 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM