我试图弄清楚如何在 UIScrollView 上覆盖 UIButton。基本上用户将能够正常使用滚动视图。但是滚动视图右上角的按钮将保持在固定位置。有什么想法吗?
3 回答
不要将 UIButton 添加为 UIScrollView 的子视图,而是添加“self.view”
在 InterfaceBuilder 中将有一个层次结构的项目列表,您将其放入视图中,将按钮从属于 scrollView 的视图拖到属于包含子视图的视图。
您的视图层次结构将如下所示
mainView
|
----Button
|
----ScrollView
代替
mainView
|
----ScrollView
|
----Button
basically It means both your button and your ScrollView will both be subViews of the exact same mainView. If your scrollView is the mainView put an empty UIView above the scrollView and insert the UIButton & UIScrollView into that
IB is a little finicky when dropping new views directly on the 'fake' interface. What you will need to do is go over to the left in the list of views and select your button view. Now drag it up to below the 'self.view' or whatever is your top level view.
YOu should notice as you raise it up and down in the list that a light blue line will appear. The width corresponds to 'subview' or 'parent' view connection. Play with it a bit to see the difference.
当您感觉舒适时,您应该能够将 Button 放在“self.view”中,而不是作为滚动视图的子视图。此外,如果您希望它出现在 TOP(物理“Z 级别”)上,则需要它位于列表中的滚动视图下方。(这指出了 CStreet 解决方案的一个微妙问题)