将UIButton锚定到UITableViewController视图的底部 [英] Anchor a UIButton to the bottom of a UITableViewController's view

查看:419
本文介绍了将UIButton锚定到UITableViewController视图的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下要求。当显示 UITableViewController 的视图时,有可变数量的行。



当行数很小时,按钮应该固定在视图的底部。



当行数较大时,删除按钮应紧接在最后一行之后。



换句话说: / p>

>



而不是:





到目前为止,我最好的尝试是设置一个 tableFooterView 使用 UITableView contentSize 更新其高度,但我遇到了各种问题。我可能会继续沿着这条道路,要求一些帮助,但首先我想知道是否有任何人有更好的解决方案。



结果必须很好地与双大小的状态栏(例如在通话期间),我的目标是iOS 6.0。

解决方案

实现这种效果的一个可能的解决方案可能需要使用两种不同的解决方案。


  1. 如果行数意味着按钮将不在屏幕上,那么使用footerView就像你一样。


  2. 如果行数表示该按钮不在屏幕之外,则


    1. 将按钮添加到tableView

    2. 实现 - (void)scrollViewDidScroll:(UIScrollView *)scrollView

    从底部的偏移可能跟随一些这样的逻辑


    1. yOffset = CGRectGetHeight(tableView.frame) - (CGRectGetHeight(button.frame)+ somePadding)

    2. yOffset + = tableView.contentOffset.y

    这意味着按钮仍会随着滚动而上下移动但你不必混淆footerView高度


    I have the following requirement. When a UITableViewController's view is displayed, there are a variable number of rows. Underneath the rows, a button should be displayed.

    When the number of rows is small, the button should be anchored to the bottom of the view.

    When the number of rows is larger, the delete button should be placed immediately after the last row.

    In other words:

    And not:

    My best attempt at this so far has involved setting a tableFooterView and trying to update its height using the contentSize of the UITableView, but I am running into all sorts of problems. I might continue down this path and ask for some help, but first I want to know if anyone has alternative (better) solutions.

    The result must play nicely with a double-sized status bar (during a call for example) and I am targeting iOS 6.0. I am not using interface builder.

    解决方案

    One possible solution to achieve this effect might have to use two different solutions.

    1. If the amount of rows means that the button will be off the screen then use the footerView like you have been doing.

    2. If the amount of rows means that the button will not be off screen then

      1. Add the button to the tableView
      2. Implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView and update the frame of the button to be offset from the bottom.

    The offset from the bottom might follow some logic like this

    1. yOffset = CGRectGetHeight(tableView.frame) - (CGRectGetHeight(button.frame) + somePadding)
    2. yOffset += tableView.contentOffset.y

    This would mean that the button still moves up and down with the scrolling but you don't have to mess with the footerView height

    这篇关于将UIButton锚定到UITableViewController视图的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆