如何在一个scrollView中有多个scrollView [英] How to have multiple scrollViews in one scrollView

查看:135
本文介绍了如何在一个scrollView中有多个scrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要启用一个水平滚动的大滚动视图。在这个scrollView中我想(让我们说)其他5个滚动视图可以垂直滚动。

I'd like to have one big scrollview with horizontal scrolling enabled. Within this scrollView I'd like to have (let's say) 5 other scrollviews which can be scrolled vertical.

任何人都可以指出我正确的方向来处理touchevents?

Can anyone point me in the right direction for how to handle the touchevents?

我正在考虑制作两个手势识别器(1个用于分接头,1个用于平移)并使用X和Y值的增量来计算水平或垂直刷卡。检查方向后,我设置了大卷轴或其中一个滚动条来启用或禁用。这是正确的approuch吗?

I'm thinking of making two gesturerecognizer (1 for tap and 1 for pan) and use the delta of the X and Y values for calculating a horizontal or vertical swipe. After I check the direction I set the big scroller or one of the scrollers to enable or disable. Is this the right approuch?

编辑:
而不是使用我上面的方法我只能添加我的5个滚动视图(垂直滚动)在一个大的scrollview(水平)中,通过添加5个scrollview作为大视图的子视图。也许这段代码可以帮助某人,所以也提供了示例代码。

Instead of using my method above I was just able to add my 5 scrollviews(vertical scrolling) in one big scrollview(horizontal) by adding the 5 scrollviews as a subview of the big one. Maybe this code can help someone out as well so provided example code as well.

for (int i = 0; i < NumberOfVerticalScrollers; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;

        UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:frame];
        scroller.directionalLockEnabled = YES;
        scroller.contentSize = CGSizeMake(320, 960);
        [self.scrollView addSubview:scroller];
}
self.scrollView.delegate = self;
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * NumberOfVerticalScrollers, self.scrollView.frame.size.height);


推荐答案

您只需要创建一个可滚动的主滚动视图水平,只需要使用 addSubView 方法在主滚动视图上添加其他滚动视图。 iOS处理所有必要的事件以正确处理滚动。您只需为每个滚动视图分配正确的内容大小 frame

You only need to create a main scrollview which can scroll horizontal, and just need to add other scroll views on main scroll view using addSubView method. iOS handle all the necessary events to handle scrolling properly. You only need to assign correct content size and frame of each scrollview.

这篇关于如何在一个scrollView中有多个scrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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