Reputation: 485
I am developing an application for iPad.
In this, I am using two UIScrollView Controllers
.
When a user scrolls the first ScrollView
, the Second ScrollView
also has to scroll programmatically.
Similarly, when a user scrolls the 2nd Scroll View then the first ScrollView
needs to scroll.
How to handle these 2 scroll views in the same View?
I have tried this:
(void)scrollViewDidScroll:(UIScrollView *)scrollView; method of the UIScrollViewDelegate.
But the scrolling animation is not smooth enough.
Please suggest to me any other way do this.
My code is:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView == sub )
{
if(sub.isDragging)
{
NSLog(@"Sub");
float x = main.contentSize.width/sub.contentSize.width;
CGPoint offset = CGPointMake((sub.contentOffset.x*x), sub.contentOffset.y);
[main setContentOffset:offset animated:NO];
}
}
else if(scrollView == main)
{
if(main.isDragging)
{
float x = main.contentSize.width/sub.contentSize.width;
CGPoint offset = CGPointMake((main.contentOffset.x/x), main.contentOffset.y);
[sub setContentOffset:offset animated:NO];
}
}
}
Upvotes: 1
Views: 346
Reputation: 953
Try to use
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated
instead of setContentOffset. And set animated to YES it will be smoother!
Upvotes: 3