2015-01-03 14 views
1

나는이 코드에서 광고 배너를 화면 상단으로 옮기려고 시도하고 많은 시행 착오를 밟았습니다. 벌써 일주일이 지났습니다. 누군가가이 문제로 나를 도울 수 있다면 나는 감격 할 것이다.이 코드로 iAd 배너를 화면 상단으로 옮길 수 없습니다.

@interface ViewController() 
{ 
BOOL _bannerIsVisible; 
ADBannerView *_adBanner; 
} 
@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
[super viewDidAppear:animated]; 

_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)]; 
_adBanner.delegate = self; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    if (!_bannerIsVisible) 
    { 
    // If banner isn't part of view hierarchy, add it 
    if (_adBanner.superview == nil) 
    { 
     [self.view addSubview:_adBanner]; 
    } 

     [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; 

     // Assumes the banner view is just off the bottom of the screen. 
     banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height); 

     [UIView commitAnimations]; 

     _bannerIsVisible = YES; 
    } 
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{ 
    NSLog(@"Failed to retrieve ad"); 

if (_bannerIsVisible) 
    { 
     [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; 

     // Assumes the banner view is placed at the bottom of the screen. 
     banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height); 

     [UIView commitAnimations]; 

     _bannerIsVisible = NO; 
    } 
} 

@end 

답변

0

변경이 라인 : 여기에

_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)]; 

:

_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, -50, 320, 50)]; 
다음 http://codewithchris.com/iad-tutorial/

코드입니다 : 이것은 떨어져 기반의 코드는 신사의 위대한 튜토리얼입니다

(여기서 -50은 광고 배너의 높이입니다.) 설정하기 전에 g 광고 배너의 프레임을 self.view.frame.size.height를 사용하여 화면 맨 아래로 가져 가면 이제 -50은 화면 위의 프레임을 움직입니다.

CGRectOffsets의 y 좌표를 뒤집을 필요가 있음을 잊지 마시기 바랍니다 (처음부터 (-)를 제거하고 두 번째 프레임에 추가). 화면 하단.

희망이 도움이됩니다.