Ser*_*yov 3 cocoa-touch objective-c uibutton uiscrollview ios
我想实现我的应用程序的以下行为:我有一个UIScrollView对我与定制的视图contentSize,我想提出一个UIButton在其左下角呆在那里,当我滚动我想按钮留它的确切位置是视图,滚动视图的内容同时滚动.
最好的方法是什么?谢谢!
Her*_*ker 10
你使用Interface Builder/Storyboard吗?如果是这样,那么只需添加滚动视图.然后添加Button但不要将该按钮添加为滚动视图的子视图.只需将其添加为兄弟姐妹.但请确保首先显示滚动视图.层次结构应如下所示:
\--View (The underlaying UIView
\--scrollView (The UIScrollView)
\-- anyView (Any subviews of the scroll view come here
\--button (The UIButton)
Run Code Online (Sandbox Code Playgroud)
通过这样做,按钮独立于滚动视图,滚动或内容大小.它可能放在滚动视图上.
编辑:快速编程(不是语法检查等)作为编程解决方案的示例.
UIScrollView *myScroller = [[UIScrollView alloc] initWith...];
UIImageView *someImage = [[UIImageView alloc] initWith...]; //Just a sample subivew.
UILabel *someLabel = [[UILabel alloc] initWith...]; //Another sample.
UIButton *myButton [[UIButton alloc] initWith...];
[self.view addSubView:myScroller];
[myScroller addSubView:someImage];
[self.view addSubView:myButton]; //it is important, that myScroller was added first
[myScroller addSubView:someLable]; //the sequence of addding subviews to the content does not matter much.
Run Code Online (Sandbox Code Playgroud)
(您可能希望在滚动条视图中有一个单独的内容视图,然后是所有子驱动程序的容器.但这不会影响我尝试解释的内容.)
| 归档时间: |
|
| 查看次数: |
1839 次 |
| 最近记录: |