自动旋转屏幕错误来自网页流量
问题描述:
我用茯苓通过AdMob合并,nomarl我的应用程序的工作不错,但回来后打了广告,并返回游戏,它错布局自动旋转屏幕错误来自网页流量
后,这是我的轮换代码
- (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,并将其设置为rootViewController
以用于AdMob视图。我现在正在做我的应用程序是这样的:
adMobView.rootViewController = [RootViewController sharedInstance];
[[[CCDirector sharedDirector] openGLView] addSubview:adMobView];
其中[RootViewController sharedInstance]
是一个类方法,它返回RootViewController的唯一实例的应用程序。请参阅https://*.com/a/10222956/1241690。
(有关的cocos2d 2.x的,第二行应该是:
[[[CCDirector sharedDirector] view] addSubview:adMobView];
)