【问题标题】:How can I position my UIView to the bottom of the screen?如何将我的 UIView 定位到屏幕底部?
【发布时间】:2012-01-08 03:20:54
【问题描述】:

我有以下代码在UITabViewController 正上方显示一个小通知栏:

- (void)showNotificationBar
{
    if(mentionsButton.hidden)
    {
        //DM button on the left
        [dmButton setFrame:CGRectMake(20,-2, 140, 35)];
        [directMessagesPill setFrame:CGRectMake(6, 7, 29, 20)];
        [dmCountLabel setFrame:CGRectMake(11, 5, 19, 21)];
        [directMessagesLabel setFrame:CGRectMake(43, 6, 81, 21)];

        //Mentions on the right
        [mentionsButton setFrame:CGRectMake(162,-2, 140, 35)];
        [mentionsPill setFrame:CGRectMake(161, 7, 29, 20)];
        [mentionCountLabel setFrame:CGRectMake(166, 6, 19, 21)];
        [mentionsLabel setFrame:CGRectMake(193, 6, 86, 21)];

    }
    else
    {
        //Mentions on the left
        [mentionsButton setFrame:CGRectMake(20,-2, 140, 35)];
        [mentionsPill setFrame:CGRectMake(6, 7, 29, 20)];
        [mentionCountLabel setFrame:CGRectMake(11, 5, 19, 21)];
        [mentionsLabel setFrame:CGRectMake(43, 6, 81, 21)];

        //DM on the right
        [dmButton setFrame:CGRectMake(162,-2, 140, 35)];
        [directMessagesPill setFrame:CGRectMake(161, 7, 29, 20)];
        [dmCountLabel setFrame:CGRectMake(166, 5, 19, 21)];
        [directMessagesLabel setFrame:CGRectMake(193, 6, 86, 21)];
    }

    if(!mentionsButton.hidden && !dmButton.hidden)
        notificationDivider.hidden = NO;

    if(!self.tabBarController.tabBar.hidden)
    {
        //CGRect frame = CGRectMake(0, 0, 320, 32);
        CGRect frame = CGRectMake(0, 500, 320, 32);
        //frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame) - frame.size.height;
        frame.origin.y = self.tabBarController.tabBar.frame.origin.y;
        notificationBar.frame = frame;

        //[self.navigationController.navigationBar.superview insertSubview:notificationBar belowSubview:self.navigationController.navigationBar];
        [self.tabBarController.tabBar.superview insertSubview:notificationBar belowSubview:self.tabBarController.tabBar];

        [UIView animateWithDuration:0.5 animations:^{
            CGRect frame = notificationBar.frame;
            //frame.origin.y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
            frame.origin.y -= frame.size.height;
            notificationBar.frame = frame;
        }];
    }
    else
    {
        CGRect frame = CGRectMake(0, 500, 320, 32);
        frame.origin.y = self.navigationController.toolbar.frame.origin.y;
        notificationBar.frame = frame;

        [self.navigationController.toolbar.superview insertSubview:notificationBar belowSubview:self.navigationController.toolbar];

        [UIView animateWithDuration:0.5 animations:^{
            CGRect frame = notificationBar.frame;
            frame.origin.y -= frame.size.height;
            notificationBar.frame = frame;
        }];
    }
}

问题是,当我将标签切换到隐藏标签栏的UINavigationController 时,UIViewUIToolbar 之间存在差距。我怎样才能重新定位它以使其下降?

【问题讨论】:

    标签: iphone objective-c cocoa-touch uiview uinavigationcontroller


    【解决方案1】:

    如果我正确理解了您的问题,应该这样做:

    我要做的是将通知栏的定位代码放在另一个函数上,因为您还在这段代码中插入了子视图。你应该在这里调用它,并且在视图中加载了这个 UIViewController 和你调用的 UINavigationController 的方法。

    正确定位通知栏的一个技巧是使用工具栏的 y 位置作为参考,因为它会自动更新。

    CGrect frame = notificationBar.frame;
    frame.y =  self.navigationController.toolbar.frame.origin.y - notificationBar.frame.size.height;
    notificationBar.frame = frame;
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多