Ошибка экрана автоповорота после возврата из веб-просмотра - PullRequest
0 голосов
/ 15 мая 2011

Я использую кокосовые орехи в сочетании с 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;
}

Спасибоза вашу помощь!

1 Ответ

1 голос
/ 20 апреля 2012

У меня раньше была похожая проблема, и я неправильно сделал, что создал новый UIViewController и установил его как rootViewController для представления AdMob. То, что я делаю сейчас в моем приложении, выглядит так:

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

где [RootViewController sharedInstance] - это метод класса, который возвращает единственный экземпляр RootViewController в приложении. См. https://stackoverflow.com/a/10222956/1241690.

(Для cocos2d 2.x вторая строка должна быть:

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

)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...