0

My App 是一个底部有 TabBar 的 iOS 应用程序。我希望 iAd 放置在 TabBar 上方。

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.

我该如何解决这个错误?

4

1 回答 1

2

不要动态添加横幅,而是将其从 UI 中拖动并添加到要显示横幅的底部

//示例代码

//在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;
    }
  }

希望这段代码对你有用..

于 2013-06-21T12:10:44.477 回答