[英]How to make an app launch in correct landscape orientation without rotating 180° at launch?
[英]How to make universal Xcode 5 app project launch in landscape orientation?
我创建了一个“单一视图应用程序”项目,并设置了所有选项以启动并仅支持横向。 但该应用程序以纵向方向启动窗口。
控制台输出表示application:didFinishLaunchingWithOptions:
之后的窗口application:didFinishLaunchingWithOptions:
是:
{{0, 0}, {768, 1024}}
我添加了一个标准系统按钮来查看ViewController,以说明应用程序是横向而不是纵向,但窗口是纵向的。
因为堆栈溢出具有白色背景,所以我在Photoshop中将右部分灰色着色,以便您可以看到它:
在application:didFinishLaunchingWithOptions:
我将窗口application:didFinishLaunchingWithOptions:
红色。 显然不是横向的。
我已经尝试过所知道的所有技巧:
1)Info.plist包含UISupportedInterfaceOrientations键,其中包含:UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight
2)Info.plist包含UISupportedInterfaceOrientations~ipad键:UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight
3)Info.plist包含初始界面方向的UIInterfaceOrientation键:UIInterfaceOrientationLandscapeRight
4)在Xcode中单击项目,然后取消选中所有纵向选项,仅检查横向选项:
5)AppDelegate和ViewController都有:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate {
return YES;
}
6)AppDelegate有:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Xcode创建了两个故事板文件。 我现在只在iPad上测试。 一个是Main_iPad.storyboard,它显示了一个纵向的视图控制器。 但它只是一个模拟的界面指标。 改为景观,正如预期没有效果。
在应用程序启动期间,我检查UIScreen界限,它也显然是肖像,而不是横向:
CGRect screenBounds = [[UIScreen mainScreen] bounds]; // {{0, 0}, {768, 1024}}
如何使其在横向上启动并创建横向窗口?
我以前遇到过类似的问题,所以也许他们有关系......
我遇到了一个问题,因为我在视图控制器的initWithNibName:bundle:
编程方式创建了我的视图initWithNibName:bundle:
无论出于何种原因,这样做会在纵向模式下定向新视图,而应用程序的其余部分正在运行横向。
我找到了两个解决这个问题的方法。 1)使用故事板而不是以编程方式创建视图或2)移动代码以从视图控制器的initWithNibName:bundle:
方法创建视图,并将其放在视图控制器的-viewDidLoad:
方法中,如下所示:
-(void)viewDidLoad {
//Create your view programmatically
UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
//Customize view
[self.view addSubview:view];
}
这是我遇到类似问题的解决方案。 虽然我认识到程序员可以通过各种方式使事情不能正常运行,但我希望这就是答案!
在界面构建器中单击View Controller ,然后在Size Inspector中将Simulated Size切换为Freeform (从Fixed ),为Width输入1024,为Height输入768。 这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.