Search code examples
ios5uiscrollviewuiscrollviewdelegate

iOS. How do I restrict UIScrollview scrolling to a limited extent?


What is the best way to set limits on the left/right scrolling of a UIScrollView. I would have thought this would be easy but all my attempts have been unsuccessful.

So, to be clear, I need a solution that will allow me to programmatically limit the scrolling extent whenever I need to during the use of my app. This will most often be in response to changes in the data being displayed.

Thanks,
Doug


Solution

  • I went with my approach of placing pan constraints in my overloaded layoutSubviews method.

    Pseudo-code:

    Calculate criteria for constraining pan
    if (pan-constraint-is-met) {
    
        Calculate pan-limit
        [self setContentOffset:limitedContentOffset];
    
    }