将两个UIScrollView连接在一起 [英] Connect two UIScrollView's together

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

问题描述

这是我一直在研究的一个棘手的iPhone问题。我在页面上有三个UIScrollViews,一个只能水平滚动,一个只能垂直滚动,一个可以水平和垂直滚动。我想将视图锁定在一起,以便水平滚动视图的水平位置与主滚动视图的水平位置匹配,同样垂直滚动视图,以便拖动主滚动视图来控制水平和垂直滚动视图。

Here's a tricky iPhone problem I've been working on. I have three UIScrollViews on a page, one that only scrolls horizontally, one that only scrolls vertically, and one that scrolls both horizontally and vertically. I want to lock the views together, so that the horizontal location of the horizontal only scrollview matches the horizontal location of the main scrollview, and the vertical scrollview likewise, so that dragging the main scrollview around controls the horizontal and vertical scrollviews.

问题是,我完全被难倒了。我在Apple文档中查看过,但似乎没有任何方法可以正式执行此操作。有人认为我曾经以某种方式克隆任何滚动视图上的任何触摸到另外两个上的点,但我不知道如何做到这一点。如果有人对此有任何想法,我将非常感激。

Problem is, I'm completely stumped. I've looked around inside the apple documentation, but there doesn't seem to be any way to do this officially. One thought that I had was to somehow "clone" any touch on any of the scrollviews to a point on the other two, but I have no idea how to do this. If anyone has any thoughts on this, I'd very much appreciate it.

编辑:我尝试了子类化UIScrollView的建议并重写touchesMoved以在另一个滚动条上调用touchesMoved观点。不幸的是,touchesMoved不会被调用滚动动作,因为UIScrollView以某种方式拦截这些动作并使用它们来控制它的滚动。我开始寻找更多低级别的东西并找到核心动画滚动图层,但理想情况下我不想从头开始重新创建UIScrollView。还在努力想出这个。

I tried the suggestion of subclassing UIScrollView and overriding touchesMoved to call touchesMoved on the other scroll views. Unfortunately, touchesMoved doesn't get called for scrolling motions as UIScrollView intercepts those motions somehow and uses them to control its scrolling. I started looking around more low level stuff and found the core animation scroll layers, but ideally I wouldn't want to recreate UIScrollView from scratch. Still trying to figure this one out.

推荐答案

我认为最简单的方法是在您的滚动视图中添加委托,实现以下方法:

I think the simplest way would be to add a delegate to your scrollviews which implement the following method:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

然后你可以检查contentOffset以检查scrollview实际滚动了多少,并相应地更新主滚动视图。

Then you can check the contentOffset to check by how much the scrollview did actually scroll, and update the main scrollview accordingly.

这篇关于将两个UIScrollView连接在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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