如何将滚动视图从滚动视图转发到另一个滚动视图
问题描述:
我有两个UIScrollViews,如果用户在滚动视图中滚动,我想让其他滚动视图也滚动。我已经阅读了一个解决方案,其中包括将pangesturerecognizer从原始平移的滚动视图传递到另一个滚动视图,但如果我这样做,原始滚动视图根本不滚动。如何将滚动视图从滚动视图转发到另一个滚动视图
我发现,有一个委托方法
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
但如果我尝试挂钩的scrollviews我的应用程序崩溃的pangesturerecognizers的代表。
希望有人能帮助我。
答
你只需要更新第二滚动型
喜欢的东西的边界: -
CGRect updateTheViewWithBounds = viewToUpdate.bounds;
updateTheViewWithBounds.origin = scrolledView.contentOffset;
viewToUpdate.bounds = updateTheViewWithBounds;
这将做的工作。
至于从评论中可以看出,我会举一个小例子。
创建两个滚动视图到的UIViewController
scrollOne = [[UIScrollView alloc] init];
[scrollOne setBackgroundColor:[UIColor greenColor]];
[scrollOne setFrame:CGRectMake(10, 20, 200, 300)];
[scrollOne setContentSize:CGSizeMake(600, 600)];
scrollOne.delegate = self;
scrollTwo = [[UIScrollView alloc] init];
[scrollTwo setBackgroundColor:[UIColor redColor]];
[scrollTwo setFrame:CGRectMake(230, 20, 200, 300)];
[scrollTwo setContentSize:CGSizeMake(600, 600)];
scrollTwo.delegate = self;
[self.view addSubview:scrollOne];
[self.view addSubview:scrollTwo];
顺应UIScrollView的代表和实现了相同的。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if([scrollView isEqual:scrollOne])
{
CGRect updateTheViewWithBounds = scrollOne.bounds;
updateTheViewWithBounds.origin = scrollOne.contentOffset;
scrollTwo.bounds = updateTheViewWithBounds;
[scrollTwo flashScrollIndicators];
}
else if([scrollView isEqual:scrollTwo])
{
CGRect updateTheViewWithBounds = scrollTwo.bounds;
updateTheViewWithBounds.origin = scrollTwo.contentOffset;
scrollOne.bounds = updateTheViewWithBounds;
[scrollOne flashScrollIndicators];
}
}
滚动任何上述scrollView将滚动scrollView。
这只会在一个滚动视图没有滚动时才起作用,对吗? :( – kohaXun 2013-03-14 13:09:59
每当第一个scrollview改变,在委托,更新相应的其他scrollView – 2013-03-14 13:41:47
你是什么意思?你的意思是scrollView:DidScroll委托方法吗?你知道我可以如何使用这种方法,仍然能够让scrollviews以不同的速度滚动? – kohaXun 2013-03-15 08:32:01