所以在 cocos2d 中(我相信我使用的是 v2.1),我这样做是为了锁定和设置方向:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
const UIInterfaceOrientation ORIENTATION = delegate.navController.interfaceOrientation;
delegate.navController.
delegate.navController.screenOrientation = ORIENTATION == UIInterfaceOrientationMaskPortrait;
UIViewController *mVC = [[UIViewController alloc] init];
[delegate.navController presentModalViewController:mVC animated:NO];
[delegate.navController dismissModalViewControllerAnimated:NO];
AppDelegate 中添加了一些功能。
我似乎无法在 iOS7 和 cocos2d v3 中获得相同的结果。
我已经深入研究了一下,正确的功能似乎已经就位,但似乎无法设置全局变量来设置方向并仅在特定时间返回我想要的方向。有人能指出我正确的道路吗?我认为我错过了一些非常小的东西,因为正确的代码似乎已经在那里了。
这是我的 AppDelegate 的代码
@implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setupCocos2dWithOptions:@{
CCSetupShowDebugStats: @(NO),
}];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
return YES;
}
-(CCScene *)startScene
{
return [HomeScreen scene];
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
我的代码从未遇到过 interfaceOrientation 函数。
想法??!?
经过几天的闲逛,我找到了解决方案:
在 AppDelegate 中我需要这个函数:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (!self.lockedToOrientation) {
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ){
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}
else {
return self.lockedToOrientation;
}
}
Where
@property UIInterfaceOrientationMask lockedToOrientation;
希望这对某人有帮助!
Cheers.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)