I have a UIView
like iPhone's Springboard. I have created it using a UIScrollView
and UIButtons
. I want to disable horizontal scrolling on said scrollview. I want only vertical scrolling. How do i accomplish this?
相关问题
- 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
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
Create two outlets, one for your view and one for your scroll view:
Then in your viewDidLayoutSubviews you can add the following code:
What we've done is collected the height and width of the view and set the scrollViews content size to match it. This will stop your scrollview from scrolling horizontally.
More Thoughts:
CGSizeMake takes a width & height using CGFloats. You may need to use your UIScrollViews existing height for the second parameter. Which would look like this:
Once I did it replacing the UIScrollView with a UITableView with only 1 cell, it worked fine.
You can select the view, then under
Attributes Inspector
uncheckUser Interaction Enabled
.since iOS7 use
//and create you page scroller with 3 pages
UPDATED: (After @EranMarom pointed out on his comment)
You can stop horizontal scrolling or vertical scrolling in the
ScrollViewDelegate
Method. Here it is how,Stops Horizontal Scrolling:
If you want to scroll horizontally, then you need to increase the contentOffset.x. Preventing that stops the scrollview scroll in horizontal direction.
Stops Vertical Scrolling:
If you want to scroll vertically, then you need to increase the contentOffset.y. Preventing that stops the scrollview scroll in vertical direction.
Above code prevents the changes in
x
andy
of ascrollview contentOffset
and it leads to stop the scrolling inscrollViewDidScroll:
method.I had the tableview contentInset set in viewDidLoad (as below) that what causing the horizontal scrolling
Check if there are any tableview contentInset set for different reasons and disable it