Search code examples
iphoneobjective-cuiscrollviewxamarin.iosaddsubview

UIScrollView - how to get rid of delay before scrolling?


I'm using a UIScrollView to display a custom UIView. When the user drags a finger across the UIScrollView, there is a noticeable delay before the display begins updating. If the user keeps touching the screen, the UIScrollView becomes very responsive after a short time. Subsequent attempts to scroll result in the same initial delay, followed by high responsiveness. This delay seriously affects the usability of the view and I would like to get rid of it.

In a test project I have written to try to get to the bottom of this issue, I have only been able to partially replicate the behaviour. The first time that the user scrolls is exactly the same - however any subsequent attempts to scroll are responsive straight away.

I have tried both setting delaysContentTouches = NO and subclassing UIScrollView so that touchesShouldBegin returns NO as suggested in multiple places online, but neither has worked.

I'm using MonoTouch on iOS 4.3, but Objective-C answers are fine. I would post code to help illustrate the issue, but since I have been unable to narrow down the problem this would be well over 1000 lines. Hopefully this is enough info to get a solution.

Does anyone know what might be causing this delay, and how I can get rid of it?


Solution

  • Some general suggestions for improving scrolling performance.

    Have your scrolling views rasterize offscreen:

    myView.layer.shouldRasterize = YES;
    

    Set that property for each sub-view on the scrollview - do not set it for the children of those sub-views or you just eat up memory that way.

    If your scrolling views do not need compositing, make sure you turn that blending off:

    myView.opaque = YES;
    

    Test using the simulator by leveraging these two features that appear on the Debug menu of the iOS Simulator:

    • Color Off-screen Rendered
    • Color Blended Layers

    If that doesn't address your problem, and you have implemented UIScrollViewDelegate, double-check to make sure you are not doing anything time consuming in those methods - for example, based on your description, you might be doing something in scrollViewDidScroll, scrollViewWillBeginDragging, or scrollViewWillBeginZooming and if you are, optimize that so it happens before scrolling even begins. Also, make sure you're not doing anything in touchesBegan.