How to Put a static UIButton Overlaying a UITableView(如何将静态 UIButton 覆盖在 UITableView 上)
问题描述
基本上,无论表格视图是否滚动,我都想在顶部创建一个静态 UIButton.但是,我尝试将 UIButton 添加为 UIView 的子视图,并使用bringSubviewToFront"方法将其置于顶部.但是,当我滚动 UITableView 时,UIButton 仍然会移动.因此,如何制作一个覆盖 UITableView 的静态 UIButton?
Basically, I wanna create a static UIButton on top whether or not the table view is scrolled. However, I tried to add the UIButton as the subview of the UIView and make it on the top by using "bringSubviewToFront" method. However, the UIButton still moves when I scroll the UITableView. Therefore, how can I make a static UIButton overlaying the UITableView?
这是我的代码:
推荐答案
你使用的是表视图控制器,所以 self.view 是表视图.表格视图是滚动视图,因此视图与其他所有内容一起滚动.
You're using a table view controller, so self.view is the table view. A table view is a scroll view, so the view scrolls along with everything else.
您应该使用带有表作为子视图的常规视图控制器.
You should use a regular view controller with a table as a subview instead.
或者,您可以尝试在 scrollViewDidScroll:
滚动视图委托方法中重置视图的框架,但我认为视图仍然会有点抖动.
Alternatively, you could try resetting the view's frame in the scrollViewDidScroll:
scroll view delegate method, but I think the view would still jitter a bit.
最后,您可以将按钮直接添加到 UIWindow
中,但这可能会带来一大堆关于旋转、动画和过渡的其他问题.
Finally, you could add the button directly to the UIWindow
, but that's likely to bring up a whole host of other problems with rotations, animations, and transitions.
这篇关于如何将静态 UIButton 覆盖在 UITableView 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!