如何在用户水平滚动时禁用垂直滚动?

lim*_*mon 2 iphone uiscrollview uiscrollviewdelegate ios

我有UIScrollView一个UIView.我正在使用我UIScrollView的pagingEnabled模式.我不想让用户同时滚动双向.我的意思是,如果用户开始水平滚动,我想禁用垂直滚动,反之亦然.我怎么能做到这一点?

谢谢.

Ber*_*rgP 6

尝试使用UIScrollView的属性directionalLockEnabled

 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
Run Code Online (Sandbox Code Playgroud)