如何防止模态UIImagePickerController旋转? [英] How to prevent a modal UIImagePickerController from rotating?

查看:372
本文介绍了如何防止模态UIImagePickerController旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完全支持旋转的应用。我在模态上添加了一个 UIImagePickerController ,其中不支持 UIInterfaceOrientationLandscape ,我无法让控制器留在肖像中。

I have an app that fully support rotation. I am modally adding a UIImagePickerController for which there is no support for UIInterfaceOrientationLandscape and I cannot get the controller to stay in portrait.

换句话说,我需要禁用 UIImagePickerController 的旋转,以便它保持纵向,而无需移除旋转对于我的应用程序的其余部分。这似乎是基本的,但我似乎找不到它。如何防止轮换?

In other words, I need to disable rotation for the UIImagePickerController so it stays in portrait, without removing rotation for the rest of my app. this seems basic, but I can't seem to locate it. How can I prevent this rotation?




更新

根据建议,我尝试使用以下代码进行子类化:

As suggested, I tried subclassing with the following code:

@interface UAImagePickerController : UIImagePickerController {
}
@end

@implementation UAImagePickerController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIDeviceOrientationIsPortrait(toInterfaceOrientation);
}
@end

这条线完全没有被击中断点...我认为必须有一些关于 UIImagePickerView

The line is not being hit at all with a breakpoint… i think there must be something funky about the UIImagePickerView

推荐答案

的时髦子类 UIImagePickerController 并让新类实现 shouldAutorotateToInterfaceOrientation:使其仅旋转为肖像,如下所示:

Subclass UIImagePickerController and have that new class implement shouldAutorotateToInterfaceOrientation: to make it rotate to portrait only, something like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

这篇关于如何防止模态UIImagePickerController旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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