I have an NSButton whose bottom is flush with its superview's, and I'd like to animate it moving up so that its top is flush with its superview's.
WWDC 2012 Session 228: Best Practices for Mastering Auto Layout mentions two ways to animate layout changes (31:16), and I'm attempting to use the CoreAnimation technique. The example below does correctly move the NSButton, but it does so instantaneously and with no animation.
[button.superview removeConstraint:pointerToBottomSpaceConstraint] ;
NSArray* topSpaceConstraintArray = [NSLayoutConstraint constraintsWithVisualFormat: @"V:|[button]"
options: 0
metrics: nil
views: NSDictionaryOfVariableBindings(button)] ;
[button.superview addConstraints:topSpaceConstraintArray] ;
[NSAnimationContext runAnimationGroup:^(NSAnimationContext* context) {
context.duration = 2 ;
context.allowsImplicitAnimation = YES ;
[button.superview layoutSubtreeIfNeeded] ;
} completionHandler:nil] ;
Can I add & remove NSLayoutConstraints and let CoreAnimation figure out how to animate the change? That seems simpler than me determining the distance between the button's old & new position, then adjusting the NSLayoutConstraint's Constant by that amount.
Add animations and effectsSelect the object or text you want to animate. Select Animations and choose an animation. Select Effect Options and choose an effect.
Adding animation simply means to add a special visual or sound effect to an object including entrance and exit effects, changes in size and colour, and even movement.
An animation effect is a preset visual effect that can be applied to the text or objects on a slide.
Slide transitions are the animation-like effects that happen when you move from one slide to the next during a presentation. Add slide transitions to bring your PowerPoint presentation to life. Select the slide you want to add a transition to. Select the Transitions tab and choose a transition.
After adding button.superview.wantsLayer = YES
, the above example animates correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With