I've got a banner that I need to display below a tab bar within a tab bar controller. Getting it to display isn't the hard part, I have that solved already, however it seems somehow that the method I am using seems to be putting it outside the normal area for input to be received.
Basically, I am using this banner as an advertisement, but I do not wish for it to cover the tab bar.
Here's the code I am using to create the banner below the tab bar:
const float footerHeight = 34.5;
const float statusBarHeight = 20.f;
const float viewHeight = 480 - statusBarHeight - bannerHeight - footerHeight;
const float viewY = 0 + statusBarHeight + bannerHeight;
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, viewHeight, 320, footerHeight)];
[footerView setContentMode:UIViewContentModeScaleToFill];
[footerView addSubview:footerButton];
[self.tabBarController.view addSubview:footerView];
[footerView release];
self.tabBarController.view.frame = CGRectMake(0, viewY, 320, viewHeight);
just for reference in some of the variables there is also a header above the top of the view as well. footerButton
is a UIButton that I have created and hooked up in IB.
I ultimately managed to work around this issue by putting a UITapGestureRecognizer
on the root UIWindow
object and then manually doing the rect cheecks to see if it is within the normal, smaller bounds of the tabBarController and forwarded the input to my footer bar otherwise
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
CGPoint touchPoint = [touch locationInView:self.window];
if ( touchPoint.y > 57 && touchPoint.y < 446 )
{
return NO;
}
return YES;
}
-(IBAction) handleTap:(UIGestureRecognizer*)sender
{
if ( sender.state == UIGestureRecognizerStateEnded )
{
//handle
CGPoint tapPoint = [sender locationOfTouch:0 inView:self.window];
if ( tapPoint.y >= 446 )
{
[footerButton clickedAd];
}
NSLog(@"(%f,%f)", tapPoint.x, tapPoint.y );
}
}