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 に答える