2010-06-10 7 views
3

내 코코스 2D 게임에서 ADBannerView라는 새 개체를 통합하려고하지만 게임이 가로 방향 일 때 화면 왼쪽에 배너가 세로로 나타납니다. 내 코드는 다음과 같습니다.Cocos2d에서 AdBannerView를 통합하는 방법

UIViewController *controller = [[UIViewController alloc] init]; 
controller.view.frame = CGRectMake(0,0,480,32); 

//From the official iAd programming guide 
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 

adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier480x32]; 

adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32; 

[controller.view addSubview:adView]; 

//Then I add the adView to the openglview of cocos2d 
[[Director sharedDirector] openGLView] addSubview:controller.view]; 

가로 (가로 모드)에서 배너가 화면 상단에 나타나기를 바랍니다.

감사합니다.

답변

1

만든 프레임을 회전해야합니다. 다음과 같이 시도하십시오 :

// lower right:-136, 295, 320, 32 lower left:-136, 135, 320, 32 upper right:136, 295, 320, 32 
UIViewController *controller = [[UIViewController alloc] init]; 
controller.view.frame = CGRectMake(136, 135, 320, 32); 
controller.view.transform = CGAffineTransformMakeRotation(M_PI/2.0); // turn 180 degrees 

//From the official iAd programming guide 
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 

adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier480x32]; 

adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32; 

[controller.view addSubview:adView]; 

//Then I add the adView to the openglview of cocos2d 
[[Director sharedDirector] openGLView] addSubview:controller.view]; 

M_PI는 cocos2d 라이브러리의 math.h에 정의되어 있습니다. 단지 pi입니다. 일단 당신이 그것을 얻으면, 당신이 그것을 필요로하는 곳에 그것을 위치시키는 rect의 처음 2 개의 숫자로 놀아주세요.

0

shouldAutorotateToInterfaceOrientation에서 뷰 프레임 크기 &의 원점을 수정해야합니다.