我创建了一个"Single View Application“项目,并将所有选项都设置为启动并仅支持横向。但该应用程序启动时的窗口是纵向的。
控制台输出显示application:didFinishLaunchingWithOptions:之后的窗口为:
{{0, 0}, {768, 1024}}我在ViewController的视图中添加了一个标准的系统按钮,以说明应用程序是横向的,而不是纵向的,但窗口是纵向的。
因为堆栈溢出有白色的背景,所以我在Photoshop中将右边的部分涂成灰色,这样你就可以看到它了:

在application:didFinishLaunchingWithOptions:中,我将窗口涂成红色。它显然不是横向的。
我已经尝试了我知道的所有技巧:
1) Info.plist包含带有: UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight的UISupportedInterfaceOrientations密钥
2) Info.plist包含and支持的接口方向~ipad key,带: 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}}如何让它在横向启动,并在横向上创建一个窗口?
发布于 2013-11-24 00:59:20
我以前也遇到过类似的问题,所以他们可能是有关联的。
我遇到了一个问题,因为我在我的视图控制器的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];
}这就是我遇到的类似问题的解决方案。虽然我认识到我们程序员有无数种方法可以让事情不以正确的方式工作,但我希望这就是答案!
发布于 2014-05-16 11:48:29
在界面生成器中单击View Controller,然后在Size Inspector switch Simulated Size to Freeform (从Fixed)中,为Width输入1024,为高度输入768。这对我很管用。
https://stackoverflow.com/questions/20162216
复制相似问题