This is a follow-up to my previous email on Scroll views.

What I actually want to is be able to swap different views (with different 
heights) in and out of the scroll view. To do this, I’m adding the different 
views as a subview of the “document" view (called contentParent below):

contentParent.subviews = [subview]

I then add constraints that pin the edges of this subview to the edges of its 
parent.

Unfortunately, this creates autolayout conflicts when autoresizing is used with 
contentParent, since the autoresizing mask has created a fixed height for 
contentParent, and this fails to match the height of the subview.

It seems that I can fix this by using autolayout on the document view 
(contentParent), so I’ve added constraints that pin the left, top, and right of 
contentParent to its superview. In order to keep IB happy I’ve also added a 
placeholder (“Remove at build time”) constraint that pins the bottom of 
contentParent to the bottom of its superview.

This seems to do what I want. I’m slightly concerned about the fact that the 
superview of contentParent is a clip view, because we don’t actually want the 
edges of contentParent to be pinned to the clip view (or it wouldn’t actually 
scroll within the clip view) - but I assume that there is some kind of magic 
that goes on behind the scenes when constraints are added to views that are 
enclosed within scroll/clip views (although I haven’t seen this discussed 
anywhere).

Jeremy

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to