I have a UIScrollView
with a UIView
inside. I want to lock the x-axis so that the view is only scrolled vertically. How do I enable directional locking?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
First, set the UIScrollView's "contentSize" to have a width that is equal to or less than the width of the UIScrollView's frame.
Next, set UIScrollView's "alwaysBounceHorizontal" to NO. This will prevent the scroll view from "rubber banding" even though you've told it there's no more horizontal content to display.
It doesn't matter what's actually inside the scroll view.
You'll be subclassing
UIScrollView
and overriding thetouchesBegan:withEvent:
method,touchesMoved:withEvent:
method, and thetouchesEnded:withEvent:
method.You'll use those methods, along with the start and end points of a touch, to calculate what kind of touch event took place: was it a simple tap, or a horizontal or vertical swipe?
If it is a horizontal swipe, you cancel the touch event.
Take a look at the source code here to learn how you might get started.