On 21 Sep 2014, at 16:44, Kyle Sluder wrote:

[…] how can I ensure the position I set for a subview’s frame in my `layout` override is not (implicitly) changed later?

You need to turn on translatesAutoresizingMaskIntoConstraints for the subviews you position manually. That way Auto Layout knows how to position them.

Thanks a lot for your quick answer, I think I got it all working now, although not without some further issues:

1. It seems my layout implementation must call [super layout] before *and* after I set my subview’s frame. If I do not call it afterwards, I get the “something may have dirtied layout in the middle of updating it” warning. Is this expected?

2. If I set translatesAutoresizingMaskIntoConstraints to YES then I effectively can’t use constraints involving the view. At least it seemed very prone to the “ambiguous layout” exception. Perhaps this is just a question of setting the proper autoresize mask? What I want is only to place and size my subview, but the subview itself contains views that ideally I would have the auto-layout system handle.

3. If allowsImplicitAnimation is enabled (layer-backed) and I read my subview’s frame property after having updated it, then I do not get back the value that I set, instead I get the interpolated value (original → new). I was under the impression that with wantsLayer set to YES only the layer tree contains the interpolated value, and the view holds the latest value. This is a problem for sub-sub-views that also have a layout override, as that method will use incorrect view bounds. My workaround was to layout the full subtree from the first view (in the view hierarchi) with a layout override.

4. If allowsImplicitAnimation is enabled then my custom layout implementation is called a dozen times after the first (true) layout pass. This is problematic because then I’ll do layout (again) and effectively suppress the animation (although only for views where I cause the frame size to change, it seems). My workaround for this was to introduce instance data to record the parameters used for the layout (like view bounds) and then check that in my layout override and only do my custom layout if the parameters have changed.
_______________________________________________

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