我的应用程序是一个iOS应用程序,底部是TabBar。我希望将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.
如何解决错误?
答案 0 :(得分:2)
不是动态添加横幅,而是从UI中拖动横幅并在底部添加要显示横幅
的位置//示例代码
//在sample.h中
#import <iAd/iAd.h> //Import header file
然后设置委托方法ADBannerViewDelegate,然后添加以下代码
IBOutlet ADBannerView *adView;
BOOL bannerIsVisible;
@property(nonatomic,assign) BOOL bannerIsVisible;
然后转到用户界面并将对象广告连接到横幅广告
// sample .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;
}
}
希望这段代码对你有用..