如何防止模态 UIImagePickerController 旋转?
我有一个完全支持旋转的应用程序。我正在模态添加一个 UIImagePickerController
,它不支持 UIInterfaceOrientationLandscape
并且我无法让控制器保持纵向。
换句话说,我需要禁用 UIImagePickerController 的旋转,使其保持纵向,而不删除应用程序其余部分的旋转。这看起来很基本,但我似乎无法找到它。如何防止这种轮换?
更新
正如建议的,我尝试使用以下代码进行子类化:
@interface UAImagePickerController : UIImagePickerController {
}
@end
@implementation UAImagePickerController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIDeviceOrientationIsPortrait(toInterfaceOrientation);
}
@end
该行根本没有被断点击中......我认为 UIImagePickerView
一定有一些奇怪的地方
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.
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?
UPDATE
As suggested, I tried subclassing with the following code:
@interface UAImagePickerController : UIImagePickerController {
}
@end
@implementation UAImagePickerController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIDeviceOrientationIsPortrait(toInterfaceOrientation);
}
@end
The line is not being hit at all with a breakpoint… i think there must be something funky about the UIImagePickerView
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在 UIViewController 中创建了 UIImagePickerController,并实现了相应的 shouldAutorotateToInterfaceOrientation 方法,并像这样呈现它
希望有所帮助。
I created my UIImagePickerController inside a UIViewController with the respective shouldAutorotateToInterfaceOrientation method implemented and presented it like this
Hope that helps.
子类
UIImagePickerController
并让该新类实现shouldAutorotateToInterfaceOrientation:
以使其仅旋转到纵向,如下所示:Subclass
UIImagePickerController
and have that new class implementshouldAutorotateToInterfaceOrientation:
to make it rotate to portrait only, something like this:您应该覆盖 _isSupportedInterfaceOrientation:,而不是 shouldAutorotateToInterfaceOrientation:
iPad 2 UIImagePickerController相机自动旋转让我发疯!
You should override _isSupportedInterfaceOrientation:, and not the shouldAutorotateToInterfaceOrientation:
iPad 2 UIImagePickerController camera auto-rotation driving me mad!
只需将其放在 ViewControllers @implementation 块上方(在 .m 文件中)
Just drop this in above your ViewControllers @implementation block (in the .m file)