Hi All,
I have a tough one that I can't figure out. I am trying to "Lock" two scrollviews where they are sitting using a UISwitch, so when you move one the other moves without snapping to the other's contentOffset.
I have a test app going with 2 scrollviews that are 1024x85 each and only scroll horizontal. Below those a UISwitch, and above the scrollviews are two labels that displays the contentOffset of both scrollviews as I move them (so I can see what's going on).
The code I have so far works and "Locks" the scrollviews together BUT, once I start sliding one of the scrollviews the other one snaps to the same contentOffset as the one i'm sliding. This displays the labels as the same number.
An example of what i'm looking for is: I slide 'scrollOne' so the label reads 1000. I slide 'scrollTwo' so its label reads 500. I lock them by turning the switch ON. Then I slide 'scrollOne' so its label reads 500. 'scrollTwo' should move as I slide 'scrollOne'. The label for 'scrollTwo' should now read zero.
Here's the code I have so far:
Code:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint p = scrollOne.contentOffset;
CGPoint r = scrollTwo.contentOffset;
// Print the labels as the scrollviews move
scrollOneLabel.text = [NSString stringWithFormat:@"%.2f", p.x];
scrollTwoLabel.text = [NSString stringWithFormat:@"%.2f", r.x];
// Flip the switch to lock the scrollviews together
if (lockSwitch.on) {
if (scrollView == scrollOne) {
scrollTwo.contentOffset = CGPointMake(scrollOne.contentOffset.x, 0);
}
else if (scrollView == scrollTwo) {
scrollOne.contentOffset = CGPointMake(scrollTwo.contentOffset.x, 0);
}
}
}
Any Ideas?
Thanks in advance for any help
Wudstock