Connect two UIScrollView's together

后端 未结 2 1850
小鲜肉
小鲜肉 2021-01-06 02:57

Here\'s a tricky iPhone problem I\'ve been working on. I have three UIScrollViews on a page, one that only scrolls horizontally, one that only scrolls vertically, and one th

相关标签:
2条回答
  • 2021-01-06 03:04

    I think the simplest way would be to add a delegate to your scrollviews which implement the following method:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    

    Then you can check the contentOffset to check by how much the scrollview did actually scroll, and update the main scrollview accordingly.

    0 讨论(0)
  • 2021-01-06 03:30

    You need to extend UIScrollView for all three uses on your screen and override the touchesMoved:withEvent: methods to call the other ones (make sure you don't end up with circular code that ends up calling itself again!).

    So, for example the code in the two-way scrolling item could be based on this:

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [horizontalScrollview touchesMoved:touches withEvent:event];
        [verticalScrollview touchesMoved:touches withEvent:event];
    }
    

    by using some additional variable (eg ControllerLastTouched) you can check that before calling the other two touchesMoved:withEvent: methods.

    This should enable you to do the "cloning" you were talking about...

    0 讨论(0)
提交回复
热议问题