cocos2d v3在应用程序使用期间重新定位屏幕 [英] cocos2d v3 re-orient screen during App use
问题描述
所以在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函数。
经过几天的愚弄,我想出了一个解决方案: / p>
在AppDelegate中我需要这个函数:
- (NSUInteger)应用程序:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(!self.lockedToOrientation){
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}
else {
return self.lockedToOrientation;
}
}
其中
@property UIInterfaceOrientationMask lockedToOrientation;
希望这有助于某人!
。
So in cocos2d (I believe I was on v2.1) I did this to lock and set the orientations:
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];
With some functions added to the AppDelegate. I cannot seem to get the same results in iOS7 and cocos2d v3.
I have dug through a bit and the proper functions seem to be in place but cannot seem to set up a global variable to set the orientation and return only the one I want at the certain time. Can someone point me down the proper path. I think I'm missing something really small cause the proper code seems to be there already.
Here's the code for my 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);
}
My code never hits the interfaceOrientation functions.
Thoughts??!?
After a couple days fooling around I figured out a solution:
in AppDelegate I needed this function:
-(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;
Hope this helps someone!
Cheers.
这篇关于cocos2d v3在应用程序使用期间重新定位屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!