在 UIImagePickerController 中强制横向 [英] Force landscape orientation in UIImagePickerController

查看:21
本文介绍了在 UIImagePickerController 中强制横向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发的新手,我正在开发我的第一个应用程序.(很抱歉,如果我问的是新手问题)

我的应用都是纵向的,除了我使用 UIImagePickerController 拍摄要在应用中使用的照片的地方,我正在做的是:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];picker.delegate = self;picker.sourceType = UIImagePickerControllerSourceTypeCamera;picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];picker.allowsEditing = NO;[self presentModalViewController:picker 动画:YES];

由于我的应用处于 纵向,我需要为 UIImagePickerController 做一些仅横向.如果我尝试使用:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

好像不能用了,因为我的 Xcode 在这行中识别出错误(可能是因为 Xcode 的版本,我不确定).而且我不确定,但似乎如果我正在为 iOS 5.1 开发,我还需要为 iOS 6.0 实现一些东西,是否正确?>

有人可以帮助我了解制作这个 UIImagePickerController 需要什么,并且只有应用中的这个视图控制器可以横向工作并且可以在 iOS 5.1 和 6 中工作吗?

问候

解决方案

根据 UIImagePickerController 类参考

<块引用>

重要:UIImagePickerController 类仅支持纵向模式.此类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的,不得修改,只有一个例外.您可以将自定义视图分配给 cameraOverlayView 属性,并使用该视图显示附加信息或管理相机界面和代码之间的交互.

因此,强制横向模式似乎不受支持且不鼓励,除非您将默认控件替换为自定义 cameraOverlayView.

I'm new to iOS development, and Im developing my first app. (so sorry if Im asking a newbie question)

My app is all in portrait orientation, except to the place where I'm using UIImagePickerController to take a picture to be used in the app, what I'm doing is:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:YES];

As my app is in Portrait, I need to make something to the UIImagePickerController be in landscape only. if I try to use:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

It seems that I can't use, because my Xcode identify as a error in this lines (probably because of Xcode the version, I'm not sure). And I'm not sure, but it seems that if I'm developing for iOS 5.1 I will need to implement something for iOS 6.0 too, is it correct?

Can someone help me to understand what is need to make this UIImagePickerController, and only this view controller in the app, work in Landscape orientation and works in iOS 5.1 and 6?

Regards

解决方案

As per the UIImagePickerController Class Reference

Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

So it looks like forcing landscape mode is unsupported and discouraged, unless you do so by replacing the default controls with a custom cameraOverlayView.

这篇关于在 UIImagePickerController 中强制横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆