Double UIScrollView synchronization - Different he

2019-08-22 09:21发布

问题:

I'm currently developping iPad application with 2 UIScrollView in the same page. On the left side, there is the content and on the right side, there are some bloc, news. These two UIScrollView are different height size.

Example : left 1000, right 2000.

I would like to synchronize the 2 UIScrollView, I explain me :

When the user scrolls on the left UIScrollView to access on the bottom, the right UIScrollView "scrolls" in the same time. If the left UIScrollView is happened to be at the bottom, and the right UIScrollView is NOT on the bottom, the right UIScrollView continue to scroll until ... it stop naturally.
And the same behavior if the user scroll on the right UIScrollView.

Do you have an idea how to resolve or to handle my problem ?

回答1:

You have to listen to the delegate method of scrollViewDidScroll then you can set the contentOffset of the second UIScrollView.



回答2:

I'll just post the solution I used in case anyone gets to this question in the future.

You don't set the contentOffset directly. You need to do a workaround. Like so:

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

Regards