Properly zooming a UIScrollView that contains many subviews(正确缩放包含许多子视图的 UIScrollView)
问题描述
我创建了一个可缩放的 UIScrollView 并向其中添加了 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?
我尝试创建另一个 UIView 并向其中添加 100 个子视图.然后在上面的方法中返回一个视图,但我不起作用(它会缩放,但一旦停止,它就不再是交互式的了).
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).
推荐答案
没错,
这也是 Apple 在 滚动查看编程指南:
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...
然后在 viewForZoomingInScrollView 委托方法中返回 Index 0 处的对象:
Then in the viewForZoomingInScrollView delegate method return the object at Index 0:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [self.scrollView.subviews objectAtIndex:0];
}
这篇关于正确缩放包含许多子视图的 UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:正确缩放包含许多子视图的 UIScrollView
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01