iOS 无法在 Interface Builder 中使 UIWindow 横向显示
我正在尝试将 MainWindow.xib 中的 UIWindow 设置为横向模式。不幸的是,这个选项在 Interface Builder 中是灰色的。我在同一个 NIB 中有一个可以设置为横向的导航控制器,但这最终在 Interface Builder 中看起来很尴尬,因为导航控制器设置为横向,但包含的窗口是纵向的。
更糟糕的是,我无法让窗口在运行时横向运行。我在导航控制器的视图中有此代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
但我不知道如何为包含的窗口指定此代码。我已经在 plist 中设置了方向,但这似乎并没有使我的视图以横向显示。
I am trying to set a UIWindow in MainWindow.xib into landscape mode. Unfortunately, this option is greyed out in Interface Builder. I have a Navigation Controller within the same NIB that can be set to landscape, but this ends up looking awkward in Interface Builder, as the Nav Controller is set to landscape but the containing window is in portrait.
What's worse is that I can't get the window to run in landscape during runtime. I have this code in the view within the nav controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
I don't know how to specify this for the containing window though. I have set the orientation in the plist but this doesn't seem to make my view display in landscape.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,您似乎希望第一个视图控制器在显示时处于横向模式。
为此,您需要在 info.plist 文件中设置“初始方向”。有一个关键。
因此,您需要做的是,使您的 xib 处于横向模式,按照上面的方法实现方法,并在 plist 中将初始方向设置为横向。
From what i can see, it seems like you want your first view controller to be in landscape mode, when displayed.
For this, you need to set the "Initial orientation" in your info.plist file. There is a key for this.
Thus, what you need to do is, Make your xib in landscape mode, implement the method as you have done above and set the initial orientation to landscape in plist.
我也遇到了 UIWindow 被强制进入纵向模式的问题。我的解决方案是在窗口和我正在操作的视图之间使用另一个视图级别。虽然不是一个完美的解决方案,但它确实有效。我希望你能解决这个问题。
I faced a problem with the UIWindow being forced into portrait mode as well. My solution was to use another view level between the window and the views I was manipulating. Though not a perfect solution it worked. I hope you get it worked out.