3

谁能解释我发生了什么事?我用这个方法

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

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

4

4 回答 4

3

改变你的shouldAutorotateToInterfaceOrientation喜欢

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

还要检查你的应用程序 plist 文件,会有一个像Supported Interface Orientations这样的,它的类型是数组,并且有4 个值从 plist 中删除肖像模式并保存。它会起作用的。请检查这个。

于 2012-06-13T19:44:53.250 回答
1

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

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

此外,确保父视图设置为自动旋转 true。shouldAutorotateToInterfaceOrientation 不起作用

于 2012-06-12T15:50:07.467 回答
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

让我知道它是否有效!

于 2012-06-13T19:53:40.523 回答
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;
}
于 2012-06-19T10:45:28.350 回答