I am working on application in it I have to work with two scroll view Simultaneous in one touch. It means if I scroll one scroll view at same time another scroll view must scroll with it.
If this is possible then how can it be done?
Implement the UIScrollViewDelegate protocol in the view controller containing both scroll views. In the:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
delegate method, get the content offset:
CGPoint offset = [scrollViewA contentOffset]; // or scrollViewB
Then set the other control with:
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
You can determine which one to change by comparing in the delegate method above:
if( scrollView == scrollViewA ) // change offset of B
else // change offset of A
Don't have to read
Generally (at least from what I know) it's bad "style" to have 2 UIScrollView
/UITableVIew
's in each other because it causes the UI to be hard to interact with. But I think if you have a valid enough use/reason for doing it then I'll show you a way to get it done.
CODE!
If it was me then I'd just override the UIScrollView
's touchesMoved
method and scroll the other UIScrollView
that way.
Within scrollView_1
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [ touches anyObject];
CGPoint newLocation = [touch locationInView: [touch view]];
CGPoint oldLocation = [touch previousLocationInView:touch.view];
CGPoint translation = CGPointMake(newLocation.x - oldLocation.x, newLocation.y - oldLocation.y);
scrollView_2.contentOffset = CGPointMake(scrollView_2.contentOffset.x + translation.x, scrollView_2.contentOffset.y + translation.y)
}
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With