简体   繁体   English

滚动带有UIButton可见的tableView

[英]Scroll tableView with UIButton visible

I have a TableView that contains a prototype cell and a UIView with a button in it. 我有一个TableView,其中包含原型单元格和带有按钮的UIView。 It looks like this: 看起来像这样:

在此处输入图片说明

I have to scroll all the way to the bottom of the tableView to get to the button. 我必须一直滚动到tableView的底部才能找到按钮。

What I am trying to achieve is to keep the button visible at the bottom while the tableView is scrolling at the upper part of the screen. 我想要实现的是在tableView在屏幕上方滚动时,使按钮在底部可见。

How can I do that? 我怎样才能做到这一点?

I didn't like the idea of ditching the UITableViewConvtroller so I ended up doing it via: 我不喜欢放弃UITableViewConvtroller的想法,所以最终通过以下方法完成了该工作:

//self.floatingActionButtonYOrigin is initialised with the initial Y origin in viewDidLoad.

override func scrollViewDidScroll(scrollView: UIScrollView) {
    let tableBounds = self.tableView.bounds
    var floatingButtonFrame = self.bottomRightButton.frame;
    floatingButtonFrame.origin.y = self.floatingActionButtonYOrigin + tableBounds.origin.y;
    self.bottomRightButton.frame = floatingButtonFrame;
}

It doesn't respect orientation changes though.. 它不尊重方向改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM