This is a UI layout issue. I need to place banner ads on the bottom of all views in an iPhone app. The banner ads are shared and only load if they are available.
Two UIViewControllers contain UITableViews that occupy the full screen. I am having two related issues that I don't know how to address. When the banner ad loads, it hides the bottom part of the table view, blocking the user from being able to select the any of the last couple of cells. Additionally, the right side index is no longer centered and sits lower than it should.
Apparently, Apple will reject an app if there is blank white space in the event that an ad does not load (correct me if I'm wrong on this), so there is a need to have the tableviews go full length if no ad is available.
Has anybody addressed this issue? What might be a best practice to overcome this? Thanks!
I figured out how to do that for usual UITableViewController
without using custom UIViewController
with UITableView
inside. The trick is to dynamically adjust position of banner view to make it always be on the bottom of visible area.
You have just add your banner view as subview and adjust table insets accordingly:
- (void)viewDidLoad
{
[super viewDidLoad];
...
//init banner and set it's frame (here we use 320x50 banner)
self.bannerView = [[UIView alloc] init];
self.bannerView.frame = CGRectMake(0, self.view.frame.size.height - 50, 320, 50);
//add as subview
[self.view addSubview:self.bannerView];
//set proper bottom inset depending on your banner height
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
}
When the table is scrolled you need to adjust banner position depending on content offset:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//refresh banner frame during the scrolling
CGRect bannerFrame = self.bannerView.frame;
bannerFrame.origin.y = self.view.frame.size.height - 50 + self.tableView.contentOffset.y;
self.bannerView.frame = bannerFrame;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With