iPhone:如何在ScrollView中滚动随机高度的UIView?
我在界面生成器中创建了 ScrollView 和 UIView (但也可以是代码)。我想向 UIView 添加随机数量的缩略图(子视图),并且如果超出屏幕可以容纳的数量,则能够上下滚动它。但是,我无法让 ScrollView 滚动。
在哪里以及如何调整 UIView 的大小并将其添加为 ScrollView 的子视图?
什么时候设置scrollView的contentSize使其随着uiview展开?我尝试创建固定的大 contentSize 但效果不佳。
我可能需要更改 IB 中的哪些属性才能使其正常工作?
我想在下一步中使 uiview 中的图像可点击。
我想我也可以在没有 IB 的情况下在代码中创建两个视图。只是不知何故无法让它发挥作用。
提前致谢 !
I have ScrollView and UIView created in interface builder (but can as well be code). I want to add random amount of thumbnails (subviews) to UIView and be able to scroll it up-down if there are more than the screen can take. Hovewer, I can't get ScrollView to scroll.
Where and how do I resize UIView and add it as a subview of ScrollView?
When do I set contentSize of scrollView to make it expand along with uiview? I tried creating fixed large contentSize but didn't work as well.
What properties in IB I might need to change to make it work?
I'd like to make the images in uiview clickable in next step.
I guess I could also make both view in code without IB. Just somehow can't get it to work.
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
//声明基本视图
//声明滚动视图并添加到基本视图
//将您的控件添加到图像视图或需要显示的内容的滚动视图
//获取最后一个控件的 y 位置并设置您的 K
float k
=最后一个控件的 y 位置 +100;(将决定滚动大小的东西)使用上面的行在运行时调整滚动视图大小。
这里的 screenSize.size.width 是 320
//declare base view
//declare scrollview and add to base view
//Add your controls to scrollview that s image view or something which is needed to display
//took last control's
y
postion and set your Kfloat k
=Last control's y position +100;(some thing which ll be decide scroll size)use above line for scroll view size adjustment at run time.
screenSize.size.width is 320 here
代码片段,
code snippet,