English 中文(简体)
如何将多个滚动视图放在一个滚动视图中
原标题:How to have multiple scrollViews in one scrollView

我希望启用一个具有水平滚动功能的大滚动视图。 在此滚动ViewIfI 中, 我喜欢有另外5个可以垂直滚动的滚动视图 。

谁能指点我正确方向 如何处理触摸活动?

我正在考虑做两个手势识别器(1个用于开关,1个用于锅盘),并使用 X 和 Y 值的三角形来计算水平或垂直擦拭。在我检查方向后,我设置了大滚动器或一个滚动器来启用或禁用。 这是正确的工具吗?


EDIT: 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);
最佳回答

您只需要创建能够向水平滚动的主滚动视图, 只需使用 < code> addSubView 方法在主滚动视图上添加其它滚动视图。 iOS 处理所有必要的事件来正确处理滚动。 您只需要为每个滚动视图指定正确的 < code> content size 和 < code> frame

问题回答

要做到这一点, 您需要简单地做一个水平滚动视图, 将其它垂直滚动视图添加为子视图 。 要处理的最大问题是, 底底滚动视图何时会水平滚动, 您应该禁用垂直滚动视图上的滚动 。

你可以监听:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

当发生这种情况时,您可以在垂直滚动视图上禁用滚动

下列各点,您可以使滚动回滚动:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签