gpt4 book ai didi

ios - 如何将平移手势从 ScrollView 转发到另一个 ScrollView

转载 作者:行者123 更新时间:2023-11-29 13:17:14 33 4
gpt4 key购买 nike

我有两个 UIScrollView,如果用户在 ScrollView 中滚动,我想让另一个 ScrollView 也滚动。我已经阅读了一个解决方案,涉及将 pangesturerecognizer 从最初平移的 ScrollView 传递到另一个 ScrollView ,但如果我这样做,原始 ScrollView 根本不会滚动。

我发现,有一个委托(delegate)方法

(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

但是如果我尝试连接 ScrollView 的 pangesturerecognizers 的委托(delegate),我的应用程序就会崩溃。

希望有人能帮助我。

最佳答案

你只需要更新第二个 ScrollView 的边界

类似的东西:-

CGRect updateTheViewWithBounds = viewToUpdate.bounds;
updateTheViewWithBounds.origin = scrolledView.contentOffset;
viewToUpdate.bounds = updateTheViewWithBounds;

这将完成工作。

从评论中看出,我举个小例子。

在 UiViewController 上创建两个 scrollView

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 委托(delegate)并实现相同的委托(delegate)。

    - (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。

关于ios - 如何将平移手势从 ScrollView 转发到另一个 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15408204/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com