Ios 如何将平移手势从一个滚动视图转发到另一个滚动视图
我有两个UIScrollView,如果用户在scrollview中滚动,我想让另一个scrollview也滚动。我读过一个解决方案,其中涉及将PangestureRecognitor从最初平移的scrollview传递到另一个scrollview,但如果我这样做,则原始scrollview根本不会滚动 我发现,有一个委托方法Ios 如何将平移手势从一个滚动视图转发到另一个滚动视图,ios,uiscrollview,uigesturerecognizer,Ios,Uiscrollview,Uigesturerecognizer,我有两个UIScrollView,如果用户在scrollview中滚动,我想让另一个scrollview也滚动。我读过一个解决方案,其中涉及将PangestureRecognitor从最初平移的scrollview传递到另一个scrollview,但如果我这样做,则原始scrollview根本不会滚动 我发现,有一个委托方法 (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimult
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
但是如果我试图连接ScrollView的PangestureRecognitors的代理,我的应用程序就会崩溃
希望有人能帮助我。您只需要更新第二个滚动视图的边界 比如:-
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];
}
}
滚动上述任一滚动视图将滚动两个滚动视图。您只需更新第二个滚动视图的边界即可 比如:-
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。您是什么意思?您是指scrollview:DidScroll委托方法吗?您知道如何使用此方法并仍然能够让scrollview以不同的速度滚动吗?@roronoazorro如果我实际上只希望滚动其中一个视图,该怎么办。。请勾选只有在一个滚动视图未被滚动时才起作用的问题,对吗?:(每当第一个scrollview更改时,请在委托中更新相应的其他scrollview。您是什么意思?您是指scrollview:DidScroll委托方法吗?您知道如何使用此方法并仍然能够让scrollview以不同的速度滚动吗?@roronoazorro如果我实际上只希望滚动其中一个视图,该怎么办。.检查问题