I put the UIView inside a scrollview in my iOS app and it does not scroll. What am I doing wrong?

微笑、不失礼 提交于 2021-01-01 09:26:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!