Set UIScrollView content dynamically with Autolayout

时间:2018-02-26 18:00:20

标签: ios

I am using Autolayout with UIScrollView in XCode 9. I wish to have a horizontal paging scrollview with 2-3 pages. I have set a ContentView as the single childview and put constraints on all edges so it aligns with the scroll view. The PageViews are then children of the ContentView.

  UIView
    UIScrollView
       ContentView
          PageView1
          ....

This works great and autolayout works for the scrollview. However I wish to change the content view size, sometimes 2 pages otherwise 3. I have an initial constraint on the ContentView width of twice the outer UIView width with priority set to 250.

If at runtime I change the ContentView frame so the width is increased, this does not get set and the ContentView remains at its original size, I imagine iOS is changing the frame back.

Anyone know how to do this?

0 个答案:

没有答案