gpt4 book ai didi

cocos2d-iphone - iOS 8 autorotate 将图像旋转出屏幕

转载 作者:行者123 更新时间:2023-12-01 15:15:35 25 4
gpt4 key购买 nike

所以我最近从我的客户那里听说了一个奇怪的问题。当他们尝试旋转屏幕时,屏幕会变黑。这似乎只是 iOS 8 的事情,因为我的最新版本只是将 iOS 8 添加到组合中。

从我的 View Controller :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

//
// There are 2 ways to support auto-rotation:
// - The OpenGL / cocos2d way
// - Faster, but doesn't rotate the UIKit objects
// - The ViewController way
// - A bit slower, but the UiKit objects are placed in the right place
//

#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait );

#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
//
// EAGLView will be rotated by cocos2d
//
// Sample: Autorotate only in landscape mode
//
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];
} else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];
}

// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
return ( interfaceOrientation == UIInterfaceOrientationPortrait );

#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
// EAGLView will be rotated by the UIViewController
//
// Sample: Autorotate only in landscpe mode
//
// return YES for the supported orientations

return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );

#else
#error Unknown value in GAME_AUTOROTATION

#endif // GAME_AUTOROTATION


// Shold not happen
return NO;
}

-(BOOL)shouldAutorotate
{
return YES;
}


-(NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscape;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}

我能够在我的设备和模拟器上重现它....

左横向 Landscape Left肖像 Portrait横向右 Landscape Right

根据这个类似的 iPad 测试,据我所知,图像实际上会自行旋转离开屏幕。我目前允许所有 4 个方向,即使游戏是横向的,因为我使用的是游戏中心,并且至少一些较旧的 iOS 需要纵向登录。我使用的是相当旧版本的 cocos2d (v1.1.0-beta2b),但我以前从未经历过这样的事情。我可能只能更改支持的方向并关闭自动旋转,但我想修复它。这是怎么回事?

最佳答案

我在为 ios8 编译时也遇到了 cocos1.0 的问题。在我的代码中,我发现我确实有一个用作 Root View Controller 的 UIViewController(它的 subview 在 Cocos2D 使用的 EAGLView 中)。

我找到的修复方法是从我的 UIViewController 中注释以下方法

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

我已经在 ios8 和 ios7 上进行了快速测试,并且可以正常工作

关于cocos2d-iphone - iOS 8 autorotate 将图像旋转出屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26204949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com