UIScrollView Scrollable Content Size Ambiguity 解决方法

转载URL:1、http://stackoverflow.com/questions/19036228/uiscrollview-scrollable-content-size-ambiguity-xcode-5-ios-7-interface-builder

                  2、http://stackoverflow.com/questions/24408256/scrollview-has-ambiguous-scrollable-content-height

                 3、http://natashatherobot.com/ios-autolayout-scrollview/



 1、First step: need to create an UIView as a subview of the UIScrollView as described below:

  • UIViewController

  • UIView 'Main View'

    • UIView 'Container View'

    • [Your content]

    • UIScrollView

wKiom1WSTe2Q_SG0AAB6_A5d_B0789.jpg

 2、  The second step is to make the UIScrollView constraints. I did this with the top, bottom, leading and trailing constraints to its superView.

 3、 Next I added the constraints for the container of UIScrollView and here is where the problem begins. When you put the same constraints (top, bottom, leading and trailing) the Storyboard gives a warning message:

"Has ambiguous scrollable content width" and "Has ambiguous scrollable content height"

Continue with the same constraints above, and just add the constraints "Equal Height" and "Equal Width" to your Container View in relation to the Main View and not to your UIScrollView. In other words the Container View's constraints are tied to the UIScrollView's superview.

After that you will not have warnings in your Storyboard and you can continue adding the constraints for your subviews.

---------------------------------------------------------------------------------------------------------


  1. Add in the UIScrollView a UIView (we can call that contentView);

  2. In this contentViewset top, bottom, left and right margins to 0 (of course from the scrollView which is the superView); Set also align center horizontally and vertically;

Finished.

Now you can add all your views in that contentView, and the contentSize of the scrollView will be automatically resized according with the contentView.


你可能感兴趣的:(create)