0
votes

I spent hours trying to get scrollview to work with autolayout. I did some good research, and read these great articles

http://natashatherobot.com/ios-autolayout-scrollview/ http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/

And I think i set up everything properly but my problem is, in my vertically scrollable scrollview, I am setting the content height explicitly to 800, but the width of the container inside has about 32 pixels cut off from the right edge. The green background is scrollview, so it fills the view correctly, but somehow either the width of the contentView is not enforced, or scrollView has some sort of insets. And the debugger says neither is the case.

You can see all the constraints in the screenshot. The content view also has a height constraint of 800 which is not expanded in the picture below...

Also interestingly when I pinned edges of scroll to the outer view, the trailing and leading alignments are set to -16 each. And not sure if this is causing the 30+ pixels problem I am having...

override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        self.contentView.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, self.contentView.frame.height)

        scrollView.frame = self.view.frame
        scrollView.contentInset = UIEdgeInsetsZero
        scrollView.contentOffset = CGPointZero
        scrollView.contentSize = CGSizeMake(320, 800)
    }

Here is the problem images and constraints

enter image description here

enter image description here

1
it won't let me upload images with links in my first post, so here are the screenshots i.stack.imgur.com/sspXm.png i.stack.imgur.com/1cWyV.pngjudopro

1 Answers

1
votes

after hours, I found out interestingly I also had to add equal widths between the scroll view and content view. Which seems completely unnecessary but it did the trick.... For your reference, I still kept the equal width between content view and outer most view, as well as pinning scroll view to the outer view, and content view to the scrollview.