我在视图控制器的 UIView 中添加了一个 FBAdView。(我将视图背景设置为红色)FBAdView 是使用 kFBAdSizeHeight50Banner 的 adSize 创建的。问题是 FBAdView 在添加时会计算其宽度,但在旋转设备后它不会再次计算其宽度
我尝试使用自动布局,但它没有用
添加FBAdview的代码(添加到带有红色背景的UILabel)
FBAdView *fbAdView = [[FBAdView alloc] initWithPlacementID:@"***************_***************"
adSize:kFBAdSizeHeight50Banner
rootViewController:self];
fbAdView.delegate = self;
[fbAdView loadAd];
[self.banner addSubview:fbAdView];
自动布局代码 - 不起作用
// Width constraint, parent view width
[self.banner addConstraint:[NSLayoutConstraint constraintWithItem:fbAdView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.banner
attribute:NSLayoutAttributeWidth
multiplier:1
constant:0]];
// Height constraint, parent view height
[self.banner addConstraint:[NSLayoutConstraint constraintWithItem:fbAdView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.banner
attribute:NSLayoutAttributeHeight
multiplier:1
constant:0]];
// Center horizontally
[self.banner addConstraint:[NSLayoutConstraint constraintWithItem:fbAdView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.banner
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0]];
// Center vertically
[self.banner addConstraint:[NSLayoutConstraint constraintWithItem:fbAdView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.banner
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0.0]];
添加横幅时打印屏幕它在旋转后适合屏幕宽度它不会改变其宽度(如其父红色视图)