开发者

iOS cannot make UIWindow landscape in Interface Builder

开发者 https://www.devze.com 2023-03-18 16:51 出处:网络
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 NIBtha

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号