Jack33
Jack33

Reputation: 121

How to synchronously scroll 'background scrollview' with 'foreground scrollview'

I have a scrollView that takes up the complete height of my screen so it only has a vertical scroll. The complete view's width is about 320 points. This view contains an array of images with a combining width of 320 points. I have it set up so it 'snaps' to every 320 points, giving you the feel you're browsing through pages. So far no problem, this is also done in the photos app from Apple.

However my images have transparency (I'm not even 100% sure that's possible but for the sake of this question, I'm assuming it is).

So beneath this scrollview I want another scrollview which automatically scrolls along with the 'upper' scrollview. However, when the upper scrollview moves 320 points to the left or right (because it 'snaps') I want the lower one only to move I don't know 50 or 60? Have to find out what works, what looks nice. For this question it doesn't really matter I just want to know how to make it. I'm sure I'll know how to tweak it to my needs once I get the bigger picture.

Upvotes: 1

Views: 248

Answers (1)

user529758
user529758

Reputation:

Have a look at my code in the - scrollViewDidScroll: method (last method in the file) https://github.com/H2CO3/MyFile/blob/master/src/MFHexEditor.m

I set the main UIScrollView's delegate to self (for example, a view controller or another designated delegate object), then observe the scroll view's position change using the @property contentOffset. In my code, the two scroll views have to scroll exactly the same amount, so then I set the secondary UIScrollView's contentOffset to the main scroll view's. You may rewrite this method as follows:

- (void) scrollViewDidScroll:(UIScrollView *)mainScrollView {

    auxiliaryScrollView.contentOffset = mainScrollView.contentOffset / 320.0 * 60.0;

}

Hope this helps.

Upvotes: 1

Related Questions