如何防止模态 UIImagePickerController 旋转?

发布于 2024-10-05 16:33:00 字数 678 浏览 0 评论 0原文

我有一个完全支持旋转的应用程序。我正在模态添加一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半世蒼涼 2024-10-12 16:33:01

我在 UIViewController 中创建了 UIImagePickerController,并实现了相应的 shouldAutorotateToInterfaceOrientation 方法,并像这样呈现它

[self.view addSubview:myImagePicker.view];
[targetVC.navigationController presentModalViewController:self animated:YES];

希望有所帮助。

I created my UIImagePickerController inside a UIViewController with the respective shouldAutorotateToInterfaceOrientation method implemented and presented it like this

[self.view addSubview:myImagePicker.view];
[targetVC.navigationController presentModalViewController:self animated:YES];

Hope that helps.

余生共白头 2024-10-12 16:33:01

子类 UIImagePickerController 并让该新类实现 shouldAutorotateToInterfaceOrientation: 以使其仅旋转到纵向,如下所示:

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

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);
}
诺曦 2024-10-12 16:33:01

您应该覆盖 _isSupportedInterfaceOrientation:,而不是 shouldAutorotateToInterfaceOrientation:

iPad 2 UIImagePickerController相机自动旋转让我发疯!

You should override _isSupportedInterfaceOrientation:, and not the shouldAutorotateToInterfaceOrientation:

iPad 2 UIImagePickerController camera auto-rotation driving me mad!

听,心雨的声音 2024-10-12 16:33:01

只需将其放在 ViewControllers @implementation 块上方(在 .m 文件中)

@implementation UIImagePickerController (portrait)

- (BOOL)_isSupportedInterfaceOrientation:(UIDeviceOrientation)orientation
{
    return UIDeviceOrientationIsPortrait(orientation);
}

@end

Just drop this in above your ViewControllers @implementation block (in the .m file)

@implementation UIImagePickerController (portrait)

- (BOOL)_isSupportedInterfaceOrientation:(UIDeviceOrientation)orientation
{
    return UIDeviceOrientationIsPortrait(orientation);
}

@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文