2014-09-05 3 views
0

Я создал простой проект hello world для cocos2d-x 3.2. Добавлен баннер AdMob. Суть добавления баннера, чтобы создать представление, а затем добавить в эту точку зрения первый содержание cocos2d-х, а затем контент баннер:Интеграция AdMob уничтожает текст ярлыка Hello World

UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[self addChildViewController:_contentController]; 
[contentView addSubview:_contentController.view]; 
[_contentController didMoveToParentViewController:self]; 
[contentView addSubview:_bannerView]; 
self.view = contentView; 

Результатом является то, что на iPhone, iPhone Retina, IPad Retina (но не в IPad) текст Hello World искажается, как это:

enter image description here

в то же время, что STATs текст не искажен:

enter image description here

Я не могу понять, что происходит и почему. Вот мой полный код:

.h файл

#import <UIKit/UIKit.h> 

@interface BannerViewController : UIViewController 

- (instancetype)initWithContentViewController:(UIViewController *)contentController; 
- (void) hideBanner; 
- (void) showBanner; 

@end 

и ее является .mm файл

#import "BannerViewController.h" 
#import "GADBannerView.h" 

@interface BannerViewController() <GADBannerViewDelegate> 

@end 

@implementation BannerViewController { 
    GADBannerView *_bannerView; 
    UIViewController *_contentController; 
    Boolean _bannerLoaded; 
} 

- (instancetype)initWithContentViewController:(UIViewController *)contentController 
{ 
    self = [super init]; 
    if (self != nil) { 
     // use kGADAdSizeBanner for a small banner in iPad 
     _bannerView = [[GADBannerView alloc] initWithAdSize: kGADAdSizeSmartBannerPortrait]; // scaled banner dependent on device size 
     _bannerView.adUnitID = @"ca-app-pub-874958723945898/8247587858"; 
     _bannerView.delegate = self; 
     _contentController = contentController; 
     _bannerLoaded = NO; 
    } 
    return self; 
} 

- (void)loadView 
{ 
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [self addChildViewController:_contentController]; 
    [contentView addSubview:_contentController.view]; 
    [_contentController didMoveToParentViewController:self]; 
    [contentView addSubview:_bannerView]; 
    self.view = contentView; 
} 

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return [_contentController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 
#endif 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [_contentController preferredInterfaceOrientationForPresentation]; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return [_contentController supportedInterfaceOrientations]; 
} 

// For animation 
- (void)viewDidLayoutSubviews 
{ 
    CGRect contentFrame = self.view.bounds; 
    CGRect bannerFrame = CGRectZero; 
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0 
    bannerFrame = _bannerView.frame; 
#else 
    bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size]; 
#endif 

    bannerFrame.origin.x = (contentFrame.size.width - bannerFrame.size.width)/2; 

    if (_bannerLoaded) { 
     //contentFrame.size.height -= bannerFrame.size.height; 
     bannerFrame.origin.y = contentFrame.size.height - bannerFrame.size.height; 
    } else { 
     bannerFrame.origin.y = contentFrame.size.height; 
    } 

    _contentController.view.frame = contentFrame; 
    _bannerView.frame = bannerFrame; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    _bannerView.rootViewController = self; 
    [self.view addSubview:_bannerView]; 

    GADRequest *request = [GADRequest request]; 
    [_bannerView loadRequest:request]; 
} 

- (void)adViewDidReceiveAd:(GADBannerView *)bannerView 
{ 
    NSLog(@"adViewDidReceiveAd"); 
    _bannerLoaded = YES; 
    [UIView animateWithDuration:0.25 animations:^{ 
     [self.view setNeedsLayout]; 
     [self.view layoutIfNeeded]; 
    }]; 
} 

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error 
{ 
    NSLog(@"adView didFailToReceiveAdWithError"); 
    _bannerLoaded = NO; 
    [UIView animateWithDuration:0.25 animations:^{ 
     [self.view setNeedsLayout]; 
     [self.view layoutIfNeeded]; 
    }]; 
} 

- (void) hideBanner{ 
    //TODO: 
} 

- (void) showBanner{ 
    //TODO: 
} 

- (void)dealloc { 
    _bannerView.delegate = nil; 
    [_bannerView release]; 
    [super dealloc]; 
} 

@end 
// </GADBannerViewDelegate> 

И я использую его в AppController.mm так:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // Override point for customization after application launch. 

    // Add the view controller's view to the window and display. 
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 

    // Init the CCEAGLView 
    CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] 
            pixelFormat: kEAGLColorFormatRGBA8 
            depthFormat: GL_DEPTH24_STENCIL8_OES 
           preserveBackbuffer: NO 
             sharegroup: nil 
            multiSampling: NO 
           numberOfSamples: 0]; 

    // Use RootViewController manage CCEAGLView 
    _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; 
    _viewController.wantsFullScreenLayout = YES; 
    _viewController.view = eaglView; 

    _bannerViewController = [[BannerViewController alloc] initWithContentViewController:_viewController]; 

    // Set RootViewController to window 
    if ([[UIDevice currentDevice].systemVersion floatValue] < 6.0) 
    { 
     // warning: addSubView doesn't work on iOS6 
     [window addSubview: _bannerViewController.view]; 
     //[window addSubview: _viewController.view]; 
    } 
    else 
    { 
     // use this method on ios6 
     [window setRootViewController:_bannerViewController]; 
     // [window setRootViewController:_viewController]; 
    } 

    [window makeKeyAndVisible]; 

    [[UIApplication sharedApplication] setStatusBarHidden:true]; 

    // IMPORTANT: Setting the GLView should be done after creating the RootViewController 
    cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView); 
    cocos2d::Director::getInstance()->setOpenGLView(glview); 

    cocos2d::Application::getInstance()->run(); 

    return YES; 
} 

Что случилось Вот?

ответ

0

Я нашел проблему. Я кажется, что есть время в часах, написанные черным цветом, как на картинке, которая на на этикетке Hello World и, следовательно, он деформирует:

enter image description here

Время отображается в бар имитаторы статус. Для того, чтобы скрыть это, я добавил это:

//fix not hide status on ios7 
- (BOOL)prefersStatusBarHidden 
{ 
    return YES; 
} 

в классе BannerViewController и вот оно!