正确缩放包含许多子视图的UIScrollView [英] Properly zooming a UIScrollView that contains many subviews

查看:53
本文介绍了正确缩放包含许多子视图的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在 Scroll View Programming Guide

只需创建一个视图,将所有子视图添加到此视图,并将新创建的视图作为单个子视图添加到scrollview ...

Just create a view, add all subviews to this view and add the newly created view as a single subview to the scrollview...

然后在viewForZoomingInScrollView委托方法中返回索引0处的对象:

Then in the viewForZoomingInScrollView delegate method return the object at Index 0:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 
{
    return [self.scrollView.subviews objectAtIndex:0];
}

这篇关于正确缩放包含许多子视图的UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆