我希望能够在我的 UITabBar 正上方显示一个 ADBannerView(它显示一个 UITableView)。不幸的是,我的横幅没有正确定位。它会出现在 UITableView 的正下方,然后当我滚动时,横幅将保留在我的 UITableView 的中间。
我希望横幅出现在 UITabBar 的正上方,并允许 UITableView 在用户拖动时在横幅后面滚动。
-(void)layoutForCurrentOrientation:(BOOL)animated
{
CGFloat animationDuration = animated ? 0.2 : 0.0;
// by default content consumes the entire view area
CGRect contentFrame = self.view.bounds;
// the banner still needs to be adjusted further, but this is a reasonable starting point
// the y value will need to be adjusted by half the banner height to get the final position
CGPoint bannerCenter = CGPointMake(CGRectGetMidX(contentFrame), CGRectGetMaxY(contentFrame));
CGFloat bannerHeight = 0.0;
// First, setup the banner's content size and adjustment based on the current orientation
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
bannerHeight = 32.0;
}
else
{
banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
bannerHeight = 50.0;
}
// Depending on if the banner has been loaded, we adjust the content frame and banner location
// to accomodate the ad being on or off screen.
// This layout is for an ad at the bottom of the view.
if(banner.bannerLoaded)
{
contentFrame.size.height -= bannerHeight;
bannerCenter.y -= bannerHeight / 2.0;
}
else
{
bannerCenter.y += bannerHeight / 2.0;
}
// And finally animate the changes, running layout for the content view if required.
[UIView animateWithDuration:animationDuration
animations:^{
self.tableView.frame = contentFrame;
[self.tableView layoutIfNeeded];
banner.center = bannerCenter;
}];
}