通过滚动1控制2个DMCircularScrollViews
Control 2 DMCircularScrollViews by scrolling 1
我正在使用在此处找到的 DMCircularScrollView 库:https://github.com/malcommac/DMCircularScrollView
库完成的是 "infinite" 循环回到开头的滚动视图。
我有 2 个 DMCircularScrollView,每个有 3 个项目。但是,每个项目的宽度都不同。在第一个中它们都是 scrollViewWidth/2,在第二个中它们等于滚动视图的宽度。如何通过滚动第一个滚动视图来控制第二个滚动视图?即:我将第一个滚动视图移动到 select 第二个项目,如何在移动第一个时自动使第二个滚动视图动画化?
阅读其他关于链接到常规 UIScrollView 的帖子后,我尝试实现委托方法 scrollViewDidScroll
并设置第二个滚动视图的内容偏移量,但该方法在这种情况下不起作用。
我想通了!我实现了以下方法:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"Test: %f", testScrollView.scrollView.contentOffset.x);
if(scrollView == threePageScrollView.scrollView) {
//[testScrollView relayoutPageItems:NSUIntegerMax];
[testScrollView reloadData];
NSLog(@"Third: %f", threePageScrollView.scrollView.contentOffset.x);
[testScrollView.scrollView setContentOffset:CGPointMake(threePageScrollView.scrollView.contentOffset.x*2, threePageScrollView.scrollView.contentOffset.y) animated:NO];
[testScrollView reloadInputViews];
}
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)sv {
[testScrollView relayoutPageItems:NSUIntegerMax];
if(sv == threePageScrollView.scrollView) {
[testScrollView reloadData];
NSLog(@"Third: %f", threePageScrollView.scrollView.contentOffset.x);
[testScrollView.scrollView setContentOffset:CGPointMake(threePageScrollView.scrollView.contentOffset.x*2, threePageScrollView.scrollView.contentOffset.y) animated:NO];
[testScrollView reloadInputViews];
}
//[self delegateSelector:@selector(scrollViewDidEndScrollingAnimation:) toDelegateWithArgument:sv];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sv
{
[testScrollView relayoutPageItems:NSUIntegerMax];
//[self delegateSelector:@selector(scrollViewDidEndDecelerating:) toDelegateWithArgument:sv];
testScrollView.currentPageIndex = threePageScrollView.currentPageIndex;
}
其中 threePageScrollView
是我滚动的那个,testScrollView
是通过代码设置动画的那个。
我正在使用在此处找到的 DMCircularScrollView 库:https://github.com/malcommac/DMCircularScrollView
库完成的是 "infinite" 循环回到开头的滚动视图。
我有 2 个 DMCircularScrollView,每个有 3 个项目。但是,每个项目的宽度都不同。在第一个中它们都是 scrollViewWidth/2,在第二个中它们等于滚动视图的宽度。如何通过滚动第一个滚动视图来控制第二个滚动视图?即:我将第一个滚动视图移动到 select 第二个项目,如何在移动第一个时自动使第二个滚动视图动画化?
阅读其他关于链接到常规 UIScrollView 的帖子后,我尝试实现委托方法 scrollViewDidScroll
并设置第二个滚动视图的内容偏移量,但该方法在这种情况下不起作用。
我想通了!我实现了以下方法:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"Test: %f", testScrollView.scrollView.contentOffset.x);
if(scrollView == threePageScrollView.scrollView) {
//[testScrollView relayoutPageItems:NSUIntegerMax];
[testScrollView reloadData];
NSLog(@"Third: %f", threePageScrollView.scrollView.contentOffset.x);
[testScrollView.scrollView setContentOffset:CGPointMake(threePageScrollView.scrollView.contentOffset.x*2, threePageScrollView.scrollView.contentOffset.y) animated:NO];
[testScrollView reloadInputViews];
}
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)sv {
[testScrollView relayoutPageItems:NSUIntegerMax];
if(sv == threePageScrollView.scrollView) {
[testScrollView reloadData];
NSLog(@"Third: %f", threePageScrollView.scrollView.contentOffset.x);
[testScrollView.scrollView setContentOffset:CGPointMake(threePageScrollView.scrollView.contentOffset.x*2, threePageScrollView.scrollView.contentOffset.y) animated:NO];
[testScrollView reloadInputViews];
}
//[self delegateSelector:@selector(scrollViewDidEndScrollingAnimation:) toDelegateWithArgument:sv];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sv
{
[testScrollView relayoutPageItems:NSUIntegerMax];
//[self delegateSelector:@selector(scrollViewDidEndDecelerating:) toDelegateWithArgument:sv];
testScrollView.currentPageIndex = threePageScrollView.currentPageIndex;
}
其中 threePageScrollView
是我滚动的那个,testScrollView
是通过代码设置动画的那个。