gpt4 book ai didi

iphone - 从 webview 返回后自动旋转屏幕错误

转载 作者:行者123 更新时间:2023-11-29 05:04:15 24 4
gpt4 key购买 nike

我使用cocos结合admob,正常情况下我的应用程序运行良好,但是在点击广告并返回游戏后,它的布局错误

这是我的轮换代码

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

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect;

if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
rect = screenRect;
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
rect.size = CGSizeMake(screenRect.size.height, screenRect.size.width);

CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [director openGLView];
float contentScaleFactor = [director contentScaleFactor];

if (contentScaleFactor != 1) {
rect.size.width *= contentScaleFactor;
rect.size.height *= contentScaleFactor;
}
glView.frame = rect;
}

感谢您的帮助!

最佳答案

我之前也遇到过类似的问题,我的错误做法是创建了一个新的 UIViewController 并将其设置为 AdMob View 的 rootViewController。我现在在我的应用程序中所做的事情如下:

adMobView.rootViewController = [RootViewController sharedInstance];
[[[CCDirector sharedDirector] openGLView] addSubview:adMobView];

其中[RootViewController共享实例]是一个类方法,它返回应用程序中RootViewController的唯一实例。引用https://stackoverflow.com/a/10222956/1241690 .

(对于cocos2d 2.x,第二行应该是:

[[[CCDirector sharedDirector] view] addSubview:adMobView];

)

关于iphone - 从 webview 返回后自动旋转屏幕错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6005941/

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