2013-06-21 2 views
0

Мое приложение - приложение iOS с TabBar внизу. Я хочу, чтобы iAd был помещен над TabBar.Fit iAd banner для 3,5 "и 4" макета

adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 
[adView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 
[self.view addSubview:adView]; 
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:adView 
                 attribute:NSLayoutAttributeBottom 
                 relatedBy:NSLayoutRelationEqual 
                 toItem:self.view 
                 attribute:NSLayoutAttributeBottom 
                multiplier:1.0 
                 constant:0]]; 

В журнале отображается:

Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7c94f90 h=--- v=--- V:[UIWindow:0x9a52530(568)]>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c93910 h=-&- v=-&- UILayoutContainerView:0x7c71920.height == UIWindow:0x9a52530.height>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c925c0 h=-&- v=-&- UITransitionView:0x7c71dd0.height == UILayoutContainerView:0x7c71920.height - 49>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c90ef0 h=-&- v=-&- UIViewControllerWrapperView:0x7868ef0.height == UITransitionView:0x7c71dd0.height>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c8fb20 h=-&- v=-&- UILayoutContainerView:0x7868190.height == UIViewControllerWrapperView:0x7868ef0.height>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c8e740 h=-&- v=-&- UINavigationTransitionView:0x7868b40.height == UILayoutContainerView:0x7868190.height>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c8d020 h=-&- v=-&- UIViewControllerWrapperView:0x7e66780.height == UINavigationTransitionView:0x7868b40.height - 64>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c8be10 h=-&- v=-&- UIView:0x7e606d0.height == UIViewControllerWrapperView:0x7e66780.height>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c8a670 h=-&- v=--& V:[ADBannerView:0x9d471f0(50)]>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7c8a630 h=-&- v=--& ADBannerView:0x9d471f0.midY == + 25>", 
    "<NSLayoutConstraint:0x7e656d0 ADBannerView:0x9d471f0.bottom == UIView:0x7e606d0.bottom>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7e656d0 ADBannerView:0x9d471f0.bottom == UIView:0x7e606d0.bottom> 

Break on objc_exception_throw to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

Как я могу исправить ошибку?

ответ

2

Вместо добавления баннера динамически, перетащите его из пользовательского интерфейса и добавить в нижней части, где вы хотите, чтобы показать баннер

// Пример кода

// В sample.h

#import <iAd/iAd.h> //Import header file 

затем установите метод делегирования ADBannerViewDelegate, а затем добавьте следующий код

IBOutlet ADBannerView *adView; 
BOOL bannerIsVisible; 
@property(nonatomic,assign) BOOL bannerIsVisible; 

а затем перейти к UI и подключить объект AdView к знамени

// выборочные .m

// Добавить методы делегата

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    if (!self.bannerIsVisible) 
    { 
     [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; 

     banner.frame = CGRectOffset(banner.frame, 0, 50); 
     [UIView commitAnimations]; 
     self.bannerIsVisible = YES; 
    } 

} 
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{ 

    if (self.bannerIsVisible) 
    { 
     [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; 
     banner.frame = CGRectOffset(banner.frame, 0, -50); 
     [UIView commitAnimations]; 
     self.bannerIsVisible = NO; 
    } 
    } 

надеюсь, что этот код полезно для вас ..

+0

Я не могу просмотрите любое добавление в симуляторе, пожалуйста, помогите мне, он показывает пустой белый прямоугольник, спасибо :) –