【问题标题】:Lock portrait and landscape in ios [duplicate]在ios中锁定纵向和横向[重复]
【发布时间】: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.,这也不起作用..,我会怎么做?你能告诉我吗?
  • 嗨,巴韦什。是不是要锁孔应用。是单页
  • 那段代码我试过但没有用。,

标签: ios iphone ios7 ios6 orientation


【解决方案1】:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

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

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

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

【讨论】:

    【解决方案2】:

    查看上图

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

    【讨论】:

      猜你喜欢
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-18
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      相关资源
      最近更新 更多