Ios – UIScrollView scrolling in only one direction at a time

iosipadiphonescrolluiscrollview

I have a UIScrollView and I want it to be able to scroll in both directions (it currently does) but only one at a time. So, for instance, if you start scrolling it horizontally, it won't move vertically at all until you let go and start moving it vertically. How could I go about doing this?

Best Answer

Set the directionalLockEnabled property to YES. From the Apple docs:

If this property is NO, scrolling is permitted in both horizontal and vertical directions. If this property is YES and the user begins dragging in one general direction (horizontally or vertically), the scroll view disables scrolling in the other direction. If the drag direction is diagonal, then scrolling will not be locked and the user can drag in any direction until the drag completes. The default value is NO