【问题标题】:shouldAutorotateToInterfaceOrientation doesn't work properlyshouldAutorotateToInterfaceOrientation 无法正常工作
【发布时间】:2012-10-25 02:52:42
【问题描述】:

如果设备是 iPhone,我想将方向锁定为纵向,如果设备是 iPad,我想允许所有方向。

我有此代码,但它不会将 iPhone 锁定为纵向模式:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    {
        return NO;

    }
    else
    {
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return YES;
    }
    return NO;

}

有什么问题?

【问题讨论】:

  • 是的,iOS 6,但它应该支持
  • 你写的东西可以在

标签: iphone locking orientation mode portrait


【解决方案1】:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);

    }
    else{
        return YES;
    }

}

试试这个。希望这会有所帮助。

【讨论】:

  • 不起作用,我认为它根本不会被调用,如果我放了就返回 NO;它仍然在旋转
【解决方案2】:
if you will navigate the view then force orientation will not work but if you will     present your view then it will work very well and it works for me. In my project all screens are in portrait mode only but only one screen is in landscape mode.   
- (IBAction)startButtonClicked:(id)sender {

CTFailure_RemedyGameViewController *remedyGameController = [[CTFailure_RemedyGameViewController alloc]initWithNibName:@"CTFailure_RemedyGameViewController" bundle:nil];
[self presentModalViewController:remedyGameController animated:NO];
[remedyGameController release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@end

【讨论】:

  • 这会将所有视图锁定为纵向,我需要所有视图控制器的所有方向,但必须锁定为纵向的除外
猜你喜欢
  • 2012-01-11
  • 2016-12-01
  • 1970-01-01
  • 2016-09-01
  • 2012-07-11
  • 2018-04-08
  • 2017-04-20
  • 2018-10-02
  • 2016-09-04
相关资源
最近更新 更多