Need Help in applying constraints to UIScrollView

可紊 提交于 2019-12-13 10:37:29

问题


I'm adding subviews programmatically. Requirement : when extra views are added the scroll should be enabled. The constraints that I applied :

To remove extra spaces at the top I wrote self.automaticallyAdjustsScrollViewInsets = false also give content size as self.scrollView.contentSize = CGSize(width: self.contentView.frame.width, height: self.contentView.frame.height*2)

But the when the view is loaded scroll is completely disabled.

Please help me


回答1:


When you using auto layout, you have to set content size at viewcontroller method, you have to override following method.

-(void)viewWillLayoutSubviews;

swift

override func viewWillLayoutSubviews() {

    }



回答2:


Try to set contentview height, based on (origin.y + height) of subview at bottom in scroll contentview.




回答3:


There are few things that you need to do, check that you have this enabled.

  1. Bounces
  2. Bounces Vertically
  3. Scrolling Enabled

If enabling those still doesn't help with the scrolling, add a Height constraint of your ContentView. You have to connect this constraint as an IBOutlet to your View Controller.

I believe your data is fetched from server, as such you have an ambiguous content height. So at where you print the contentSize of value (375.0,1334.0) in your question, add this line of code and you should be able to scroll thereafter.

YourHeightConstraint.constant = self.scrollView.contentSize.height


来源:https://stackoverflow.com/questions/41951644/need-help-in-applying-constraints-to-uiscrollview

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