Search code examples
iphoneiosuiscrollviewuiscrollviewdelegate

how to disable vertical scrolling while user scrolls horizontally ?


I have a UIScrollView in a UIView. I'm using my UIScrollView in pagingEnabled mode. I don't want to allow users scroll bidirectionnally at the same time.What i mean is,if user starts to scroll horizontally, i want to disable vertical scrolling and vice-versa. How can i accomplish that ?

Thank you.


Solution

  • try to use property directionalLockEnabled of UIScrollView

     directionalLockEnabled A Boolean value that determines whether
     scrolling is disabled in a particular direction
    
     @property(nonatomic, getter=isDirectionalLockEnabled) BOOL
     directionalLockEnabled Discussion 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
    
     Availability Available in iOS 2.0 and later. Declared In
     UIScrollView.h