gpt4 book ai didi

ios - 横向模式下的 UIImagePickerViewController

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:48 25 4
gpt4 key购买 nike

enter image description here我正在开发完全处于横向模式的应用程序。在其中一个 View 中,我需要使用叠加 View 打开相机(UIImagePickerController)。但是当我点击按钮打开相机时,它会因这个问题而崩溃,即原因:

'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

我也把这一行放在 viewcontroller 中但没有效果。

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

请给我一些让它工作的想法。

最佳答案

如果您使用 UINavigationController 作为基础 View Controller ,您提供的代码片段根本不起作用。因为您将该代码添加到 UIViewController 但它已经嵌入到 UINavigationController 中。

要克服这个问题,您必须创建 UINavigationController 的子类,并将与景观相关的代码添加到该子类中。然后将这个子类分配给 Storyboard 的基础 Navigation Controller。那么这个问题就迎刃而解了。

这是您的导航 Controller 子类的 .h 文件

@interface YourCustomNavigationController : UINavigationController
@end

并将其添加到您的导航 Controller 子类的 .m 文件中

- (BOOL)shouldAutorotate
{
//returns true if want to allow orientation change
return YES ;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}

并确保使用界面构建器的身份检查器将此类分配给您的基本导航 Controller 。

项目设置,

enter image description here

编辑:

您可以在横向模式下呈现一个 UIImagePickerController。不管文档怎么说,您实际上都可以对其进行子类化,并且可以覆盖它的功能以在横向模式下工作。 (至少它在 iOS 7 上工作)

为此,您必须创建 UIImagePickerController 的子类并将以上行添加到该子类。项目设置必须与屏幕截图相同(必须至少勾选一种横向模式和一种纵向模式)。

然后在呈现相机时使用该子类化的 ImagePicker Controller 。它会在横向模式下成功加载相机。但是标准的相机控制会错位和困惑。因此,最好隐藏 defaultControlls (picker.showsCameraControls = NO;),就像您所做的那样,并改用叠加 View 。

关于ios - 横向模式下的 UIImagePickerViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22170662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com