Re: Custom layout and constraints
Re: Custom layout and constraints
- Subject: Re: Custom layout and constraints
- From: Allan Odgaard <email@hidden>
- Date: Wed, 24 Sep 2014 20:49:33 +0200
On 21 Sep 2014, at 22:51, Allan Odgaard wrote:
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.
This remains a problem for me but I have the cause somewhat isolated.
If any of my subviews have translatesAutoresizingMaskIntoConstraints set
to YES then when I trigger the animation, the system will first do the
layout and then start it (expected).
However, when it, as part of the animation, changes the frame of one of
the views with translatesAutoresizingMaskIntoConstraints set to YES then
it will trigger a setNeedsLayout: on my container view, which will then
do a re-layout, setting all the frames to the same as last time, but
this will kill the animation, presumably because the frame of the
animated objects were changed outside an implicit animation group.
The stack trace of this unwanted setNeedsLayout: is:
+[NSAnimationManager performAnimations:]
⋮
-[NSView setFrameSize:]
-[NSView(NSConstraintBasedLayout)
_autoresizingConstraints_frameDidChange]
-[NSLayoutConstraint _setSymbolicConstant:constant:]
-[NSLayoutConstraint _tryToChangeContainerGeometryWithUndoHandler:]
-[NSISEngine
tryToChangeConstraintSuchThatMarker:isReplacedByMarkerPlusDelta:undoHandler:]
-[NSISEngine
constraintDidChangeSuchThatMarker:shouldBeReplacedByMarkerPlusDelta:]
-[NSISEngine _coreReplaceMarker:withMarkerPlusDelta:]
-[MyContainerView setNeedsLayout:]
As a workaround I am storing all my subview frames and in -layout I only
update them if the computed value is different than the last computed
value, this way, the unwanted calls to -layout does not kill the
animation.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden