简体   繁体   English

在IOS5中禁用横向定向

[英]Disable Landscape Orientation in IOS5

I want to eliminate Landscape Orientation in my application, which is built for IOS 5. In IOS 6 I know this is possible - but it doesn't seem to be working for me in the earlier version. 我想消除为IOS 5构建的应用程序中的“横向方向”。在IOS 6中,我知道这是可能的-但在早期版本中,它似乎不适用于我。

I am setting only two orientations in my plist file (Portrait w/Home Button on Top and Portrait w/Home Button on Bottom). 我在plist文件中仅设置了两个方向(顶部带有“主页”按钮的肖像和底部带有“主页”按钮的肖像)。 Regardless, Landscape still crops up in IOS 5. 无论如何,Landscape仍在IOS 5中出现。

Is there something further I need to do to eliminate this from happening? 我还需要做些其他事情来消除这种情况吗?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
   // return (interfaceOrientation == UIInterfaceOrientationPortrait);
   if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
 {
   return NO;
 }
 else
 {
   return YES;
 }

}

write this code in .m file for ios5 orientation 将此代码写入.m文件以实现ios5定向

let me know it is working or not.... 让我知道它是否有效....

Happy Coding!!!! 编码愉快!!!

This will work. 这将起作用。 Go to storyboard deselect the orientation you don't want and in view controller, write this code: 转到情节提要中,取消选择不需要的方向,然后在视图控制器中编写以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation==UIInterfaceOrientationPortrait );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM