在ios中锁定纵向和横向[重复]

Posted

技术标签:

【中文标题】在ios中锁定纵向和横向[重复]【英文标题】:Lock portrait and landscape in ios [duplicate] 【发布时间】:2014-08-09 11:02:53 【问题描述】:

如何在ios中锁定风景。我尝试了很多方法但没有成功,任何人都可以分享锁定风景的最新代码。

-(void) portraitLock 
    BSEAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
    appDelegate.screenIsPortraitOnly = true;


- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

    return UIInterfaceOrientationMaskPortrait;


+(BOOL)shouldAutorotate

    return NO;


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

    return (interfaceOrientation == UIInterfaceOrientationPortrait);


【问题讨论】:

当你想要风景时为什么要返回UIInterfaceOrientationMaskPortrait?据我所知,shouldAutorotate 需要是实例方法(-),而不是类方法(+) 我返回 No 和 Yes.,这也不起作用..,我会怎么做?你能告诉我吗? 嗨,巴韦什。是不是要锁孔应用。是单页 那段代码我试过但没有用。, 【参考方案1】:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);

从 IOS6 开始, shouldAutorotateToInterfaceOrientation 代替 willRotateToInterfaceOrientation 或 didRotateFromInterfaceOrientation 被贬值

您还应该在属性检查器中将视图方向更改为横向。

如果您的整个应用程序要以横向显示,您还可以将 UISupportedInterfaceOptions 添加到您的应用程序 info.plist 并指定横向。

【讨论】:

【参考方案2】:

查看上图

只勾选纵向模式。,,,,

【讨论】:

以上是关于在ios中锁定纵向和横向[重复]的主要内容,如果未能解决你的问题,请参考以下文章