在iPad中锁定横向模式

时间:2013-05-06 15:55:54

标签: ios ipad

我正在使用此代码锁定iOS应用程序的横向模式。

#pragma mark Orientation handling

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

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

它在iPhone上运行良好但在iPad上无法正常工作。它不会锁定横向模式。

需要一些指导。

4 个答案:

答案 0 :(得分:1)

此代码不正确:

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

UIInterfaceOrientation不是UIInterfaceOrientationMask。尝试这样的事情:

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

话虽如此,如果您尝试将应用程序锁定为横向模式,此处还有其他多个问题 - 例如,您的supportedInterfaceOrientations仅列出纵向模式,而不是横向模式!

答案 1 :(得分:0)

理想情况下,只需在评论中将其设置在摘要标签中即可。如果您真的想在代码中执行此操作,则只能在AppDelegate类中设置为rootViewController的任何内容中使用。

答案 2 :(得分:0)

在iOS 6中我使用:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

如果您有NavigationController,则可以将该方法添加到类别。

答案 3 :(得分:0)

我用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
           interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
相关问题