ios - 如何让 iOS 7 iPhone 应用旋转到所有界面方向?

标签 ios iphone objective-c

我正在开发一个 iPhone 应用程序。现在我所有的 View Controller 都旋转到纵向、横向左侧和横向右侧(开箱即用的 iPhone 应用程序的默认行为)。我想要的是我的应用程序设置,应用程序范围,包括对所有界面方向的支持。我该如何做到这一点?我在项目级别选择了所有界面方向,这没有任何区别。这是一张照片:enter image description here

现在,当我在 iPhone 上测试我的应用程序时,它拒绝旋转到 UIInterfaceOrientationPortraitUpsideDown .为什么?

好的,一旦我们弄清楚了,就会有一个后续问题......我的应用程序中有一个 View Controller ,我只想支持 UIInterfaceOrientationPortraitUIInterfaceOrientationPortraitUpsideDown我怎样才能做到这一点?我的 Controller 中有以下代码,但它不起作用:

// The following method never gets called (but wanted to
// include this to show that I've tried it).
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

// This method does get called but has no effect. The VC that this method
// belongs to rotates to all interface orientations except for
// UIInterfaceOrientationPortraitUpsideDown which is definitely
// not what I want...
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

// This method never gets called either and therefore has no effect...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

请注意,我的应用程序是基于 Storyboard 的(如果这有什么不同的话)。任何帮助将非常感激!谢谢。

最佳答案

按照 Landscape Mode ONLY for iPhone or iPad 中的说明进行操作并在执行此操作时添加evey界面方向,它将支持所有方向。

更改您的应用程序的Info.plist文件:

添加 Supported interface orientations行到您的应用程序的Info.plist具有所有支持的界面方向的文件

row's

将支持的界面方向添加到“支持的界面方向”。
(Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right)

Supported Interface Orientations

关于ios - 如何让 iOS 7 iPhone 应用旋转到所有界面方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20775232/

相关文章:

html - Nuxt.js:<输入类型 ="search"> 不起作用

iphone - Cocos2d CCSprite 类获取图像文件的名称

iphone - CIFilter 集成仅适用于 CISepiaTone

ios - MKMapView 忽略 iOS 11 和 iPhone X 上的安全区域

ios - 从 plist 中检索后无法释放对象

ios - 如何检查强制退出是否已禁用通知

ios - counter++/counter--未按预期工作

ios - 无法将 NSString 从 kABBirthdayProperty 转换为 NSDate

objective-c - 使用 Objective-C 写入 XML 文件

ios - 供应配置文件和存档