GameCenter横向在iPad上不起作用

时间:2012-06-10 10:28:03

标签: ios ipad game-center

任何人都可以解释一下发生了什么吗?我用这个方法

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

为matchmakerViewController提供横向方向。它可以在iPhone甚至iPad模拟器上完美运行,但不能在iPad设备上运行。当我在iPad上运行应用程序时,matchmakerViewController以纵向方向大量出现。怎么了?我如何解决它?感谢

4 个答案:

答案 0 :(得分:3)

更改您的shouldAutorotateToInterfaceOrientation

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

同时检查您的应用程序plist文件,,如支持的界面方向,它的类型将是数组,并且将具有 4值从plist中删除纵向模式并保存。 它会工作。请检查一下。

答案 1 :(得分:1)

(这很可能不是你的问题,但我使用下面的代码并且工作正常)

return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
interfaceOrientation == UIInterfaceOrientationLandscapeRight)

此外,请确保将父视图设置为autorotate true。 shouldAutorotateToInterfaceOrientation doesn't work

答案 2 :(得分:1)

这是优雅的解决方案,通过类别,扩展GKMatchMakerViewController,相同的解决方案将适用于任何其他游戏中心视图,如排行榜视图和成就视图:

.h文件

#import <Foundation/Foundation.h>
#import "GameKit/GameKit.h"

@interface GKMatchmakerViewController(LandscapeOnly)



-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;

@end

.m文件

#import "GKMatchmakerViewController-Landscape.h"

@implementation GKMatchmakerViewController(LandscapeOnly)


-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

   return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);


}

@end

让我知道它是否有效!!

答案 3 :(得分:0)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}


also check parent controller maybe some controller return YES

or try 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation==UIInterfaceOrientationPortrait)
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    else 
        return NO;
}