问题
In my storyboard I put the UIScrollView
on my UIViewController
. Inside I put a UIView
with a UIButton
, but when I run the app I cannot scroll the UIView
. What am I doing wrong?
This is how the hierarchy looks:
and the properties of scroll view:
and the view (which has a bigger size than scrollview) :
How can I make it scrollable?
回答1:
From your image it's look like you are using autolayout. So to make view scrollable you need to set the constraints to scrollview and its sub view.
Constraints for scrollview : Top, Trailing, Bottom, Leading and equal width to superview
Constraints for view(inside scrollview) : Top, Trailing, Bottom, Leading, equal width to superview and height(whatever you want to set).
After giving these constraints your view will be scrolled.
回答2:
Set the contentSize property on the ScrollView. It should scroll then.
回答3:
it may be of AutoLayout problem. if you want to scroll up-down the view then make centre horizontal layout. and make proper auto layout.
self.scrollView.contentSize = CGSize(self.view.frame.size.width, view.frame.size.height);
回答4:
deselect the safe area zone in the properties tab
回答5:
Set the height of Scroll View more than Screen height.Then it should be work
来源:https://stackoverflow.com/questions/36978375/i-put-the-uiview-inside-a-scrollview-in-my-ios-app-and-it-does-not-scroll-what