i have a scrollView. i want it to scroll only in one direction(VERTICAL). Is there a way in which i can lock the horizontal scrolling...?? ...
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- how do you prevent page scroll in textarea on mobi
相关文章
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Gallery space at beginning and end
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
should help. I just locked my scroll view horizontally, by doing the similar technique.
The scrollView is only scrollable horizontally if you set the contentSize width bigger than the scrollView frame. If you set the contentSize width to the same as the scrollview it won't scroll. For example
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,100,100)] [scrollView setContentSize:CGSizeMake(100, 300)]
The safest and most successful method I've found to constrain the movement of a scroll view is to subclass UIScrollView and override setContentOffset:animated: and setContentOffset: methods (code below).
The advantage of overriding these methods is that it directly alters the requested contentOffset before any of the UIKit code starts to act on it, avoiding any of the side effects that can occur when modifying the contentOffset in scrollViewDidScroll: or other UIScrollViewDelegate methods.
It takes just a few minutes to create the new subclass, and it works like a charm.
In my case the contentSize was higher than the UIScrollView for x and y. For me meronixe's answer worked out quite well, but was for my needs not quite complete. Unfortunately the horizontal scrollbar was still visible.
This I could change with the following code in