UIView cocos2d Support

167 views Asked by At

I'm following a tutorial to add banner in my app, but I don't understand a thing, here:

"FOR SHOW BannerView FIRST CREATE A UIView AND ADD IT TO TOP OF ROOT UIView :

UIView *adView = [[UIView alloc] initWithFrame:adRect]; 
         [[CCDirector sharedDirector].view addSubview:adView];

" THEN ADD BannerView TO IT:

[[MyAdMobController sharedController] addBannerToView:adView];

where he says to create a UIView, It means that I have to create a new scene? because i don't know exactly what is a UIView (i'm a beginner), someone can give me an example of what i have to do?

2

There are 2 answers

0
StackBuddy On

The cocos2d view is a view and everything it contains can only be "in" this cocos2d view so you need to create a layer above this cocos2d layer I would suggest if you want to use UIkit to use CCUIViewWrapper

.h

 CCUIViewWrapper *wrapper;
@property (assign, nonatomic)CCUIViewWrapper *wrapper;

.m

#import "CCUIViewWrapper.h"

//create wrapper to hold UILabel above cocos2d layer
wrapper = [CCUIViewWrapper wrapperForUIView:label];
float padding = 10;
wrapper.contentSize = CGSizeMake(500+padding, label.frame.size.height/2+padding);
[self addChild:wrapper];
wrapper.position = ccp(size.width/2, size.height/2+label.frame.size.height/2);

look up github.com CCUIViewWrapper.h CCUIViewWrapper.m

0
Asdrubal On

In order to add a UIView to your Cocos2d project you have to add it to the window. The director creates and handles the main Window and the Cocos2D view. CCDirector inherits from CC_VIEWCONTROLLER which is equivalent to UIViewController. The UIView isn't a new scene it is a "visible object" that is added to your view via the CCDirector.

(your eyes)

adMobBanner
    |
  adView
    |
  Window

 (Device)

all you are really doing is creating a box to sit on top of the window for the banner to fit into.