繁体   English   中英

在iPad中锁定风景模式

[英]Locking the Landscape Mode in iPad

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

#pragma mark Orientation handling

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

-(BOOL)shouldAutorotate
{
    return YES;
}

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

在iPhone中可以正常工作,但在iPad中不能正常工作。 它不会锁定风景模式。

需要一些指导。

此代码不正确:

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

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

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

话虽这么说,如果你想你的应用程序锁定到风景模式,这里还有其他多种问题-例如,你的supportedInterfaceOrientations只列出肖像模式,而不是横向!

理想情况下,只需按照评论中的说明在摘要标签中进行设置即可。 如果您确实想在代码中执行此操作,则仅在您设置为AppDelegate类中的rootViewController的任何位置中都可用。

在iOS 6中,我使用:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

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

我用:

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

暂无
暂无

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

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