获取 UITabBar 下方的输入

发布于 2024-12-19 01:03:57 字数 855 浏览 0 评论 0原文

我有一个横幅,需要在选项卡栏控制器内的选项卡栏下方显示。让其显示并不是困难的部分,我已经解决了这个问题,但是不知何故,我使用的方法似乎将其置于接收输入的正常区域之外。

基本上,我使用这个横幅作为广告,但我不希望它覆盖标签栏。

这是我用来在选项卡栏下方创建横幅的代码:

    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);

仅供参考,在某些变量中,视图顶部上方还有一个标题。 footerButton 是我在 IB 中创建并连接的 UIButton。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福%小乖 2024-12-26 01:03:57

我最终设法解决了这个问题,方法是在根 UIWindow 对象上放置一个 UITapGestureRecognizer ,然后手动执行矩形检查以查看它是否在正常的较小范围内tabBarController 并将输入转发到我的页脚栏,否则

- (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 );
    }
}

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 );
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文