If you have ever struggled to get autolayout to play nice with a UIScrollView or just given up entirely and done it in code instead then you might be interested in IKScrollView. It allows you to easily use a scrollview with autolayout.
Using IKScrollView is very simple and requires 0 to 1 line of code.
Add a UIScrollView to your view controller and change its class type to IKScrollView.
Add a free floating UIView to your view controller. (i.e. a view that is not part of the view hierarchy). We add this outside the view controller hierarchy so that nothing interferes with its autolayout constraints.
Connect the outlet from your IKScrollView's contentView property to the content view.
Build your content view with autolayout however you want just like a normal interface! In the example here my content view is designed for vertical scrolling (the default for IKScrollView).
IKScrollView allows you to alter how the content view is sized with the sizeMatching property. The possible values are:
SizeMatching.Width: The content view will keep its height and be sized to the width of theIKScrollView(This is the default setting)SizeMatching.Height: The content view will keep its width and be sized to the height of theIKScrollViewSizeMatching.Both: The content view will be sized to match the width and height of theIKScrollViewSizeMatching.None: No resizing will happen to the content viewSizeMatching.Dynamic: Allows you to supply a closure for the width and height that is used to size the content, eg:
myScrollView.sizeMatching = .Dynamic(
width: { self.view.bounds.size.width },
height: { calculateScrollHeight() }
)
Install via cocoapods by adding the following to your Podfile
pod "IKScrollView", "~>1.0"
or manually by adding IKScrollView.swift to your project.
There is an included app so you can see it in action.






