关于 UIScrollView 和 UIImageViews 的问题
我正在制作一个 iPad 应用程序,它将同时显示 6 个并排的 UIImageView(每行 3 个)。我希望它是可滚动的,这样我最多可以显示 15 个。所以它基本上就像 5 行,每行 3 个 UIImageView。
我假设我必须以编程方式定位 UIImageViews 而不是使用 IB - 这是正确的吗?如果是这样,我该如何定位他们的立场?所以我知道前 6 个 UIImageView 的位置,但是其余的呢?如何让它们以可滚动的方式出现在 UIScrollView 上?
有没有办法也使用 IB 来做到这一点 - 或者都是通过编程完成的?
感谢您的帮助,
I am making an iPad app that will display six, side by side UIImageViews at once (3 on each line). I want it to be scrollable so I can display up to 15. So its basically like 5 rows of 3 UIImageViews.
I assume I will have to position the UIImageViews programatically and not using IB - is this right? If so, what do I put their positions as? So I know the positions for the first 6 UIImageViews, but what about the rest? And how do I make them appear on UIScrollView in a scrollable manner?
Is there a way to do that using IB too - or is it done all programatically?
Thank you for your help,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在代码中定位它们
您可以像这样定位 UIImageView:
这将创建一个图像视图并将其放置在滚动视图中的 0, 0 处,宽度和高度为 50。
您需要像这样定位元素,然后当您获取将在屏幕外的元素,您继续像这样:
这将元素放置在滚动视图中的屏幕外,
以使 scollview 滚动,您需要将滚动视图的 contentSize 设置为大于屏幕,即。所有元素的大小在一起
因此,如果您有 6 个高度为 500 像素的图像,则 contentSize 的高度将为 6 x 500
要设置内容大小:
myScrollView.contentSize = CGSizeMake(768, 3000);
You need to position them in code
You can position a UIImageView like so:
This creates an image view and places it at 0, 0 in the scrollview with a width and height of 50.
You need to positon your elements like so, then when you get to the elements that will be offscreen you keep going like:
This positions the element offscreen in the scrollview
to make the scollview scroll you need to set the contentSize of the scrollview to be bigger than the screen ie. the size of all your elements together
So if you have 6 images that are 500 pixels in height the height on your contentSize will be 6 x 500
To set the content size:
myScrollView.contentSize = CGSizeMake(768, 3000);
不,不需要通过代码创建图像,您可以通过创建视图控制器并在其 xib 中根据需要添加三个 UIImageView 来完成此操作,然后将页面控件与 UIScrollView 一起使用,有关更多详细信息,请遵循教程 -
http://www.edumobile.org/iphone/iphone-programming-tutorials/ pagecontrol-example-in-iphone/
No its not necessary to create images by code you can do it by making a view controller and in its xib add three UIImageView as you want and then use a page control with UIScrollView and for more detail follow the tutorial -
http://www.edumobile.org/iphone/iphone-programming-tutorials/pagecontrol-example-in-iphone/