题
我的应用程序中有 MainWindow.xib。
在 Interface Builder 中,我将主窗口从纵向旋转为横向,然后在其上放置了一些 UIControl。
比我保存它。
之后,当我运行该应用程序时,尽管在设计期间我以横向模式制作了所有内容,但它始终以纵向模式显示内容。
请帮我
解决方案
IB只是设置您的XIB文件。这是管理方向的视图控制器。
默认的UIViewController或UINavigation控制器具有有关此信息。
具体而言,需要过载
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ? NO : YES);
}
看一看的UIViewController中的文件以获得更多信息。
其他提示
除了重写 shouldAutorotate 来说明您支持的方向之外,您还应该在 info.plist 文件中设置“初始界面方向”键来设置您的首选初始方向。
有关详细信息,请在“横向模式下启动”中搜索 iPhone 应用程序编程指南.
不隶属于 StackOverflow