正确缩放包含许多子视图的 UIScrollView
我创建了一个可缩放的 UIScrollView 并向其添加了 100 个子视图(平铺)。视图左右滚动完美。但是,我想允许缩放。
为此,我读到我的委托需要实现:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return ???;
}
我见过只有一个子视图需要缩放的示例,因此它们在该方法中返回该子视图。然而,就我而言,我还有更多。进行缩放的正确方法是什么?
我尝试创建另一个 UIView 并向其中添加 100 个子视图。然后返回上述方法的一个视图,但我不起作用(它会缩放,但一旦停止,它就不再具有交互性)。
I created a zoomable UIScrollView and added 100 subviews to it (tiled). The view scrolls perfectly left and right. However, I'd like to allow zooming.
To do so I read that my delegate needs to implement:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return ???;
}
I have seen examples that have only one subview to zoom, so they return that subview in that method. In my case, however, I have a lot more. What is the proper way to do the zooming?
I tried creating another UIView and adding the 100 subviews to that one. And then return that one view on the method above, but I doesn't work (it zooms but once it stops, it's not interactive any more).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确切地说,
这也是苹果在 中提到的内容滚动视图编程指南:
只需创建一个视图,将所有子视图添加到该视图,并将新创建的视图作为单个子视图添加到滚动视图...
然后在 viewForZoomingInScrollView 委托方法中返回索引 0 处的对象:
Exactly,
This is what Apple also is mentioning in the Scroll View Programming Guide:
Just create a view, add all subviews to this view and add the newly created view as a single subview to the scrollview...
Then in the viewForZoomingInScrollView delegate method return the object at Index 0:
我创建了一个视图,在其中添加了所有内容:
而不设置其框架。
当我向其中添加所有子视图后,将其框架设置为足够大以容纳所有平铺子视图时,问题就解决了。
I created the view where I added everything using:
without setting its frame.
The problem was solved when, after adding all the subviews to it, I set its frame to something large enough to accommodate all the tiled subviews.
您必须将要添加的视图作为子视图返回到滚动视图。
例如:如果要将图像视图添加到滚动视图,则编写
You have to return what your going to add views to scroll view as a subviews.
Ex: If you are adding image view to scroll view then write