Note that there are some explanatory texts on larger screens.

plurals
  1. POSelectively overriding CALayer implicit animations
    text
    copied!<p>I have a CALayer subclass that is constrained to the width of the parent layer, but a fixed height. I want the implicit animation disabled for resizing the window but enabled whenever I set the height of the layer.</p> <p>To disable the animation when the window is resized I set the layers actions to</p> <pre><code>NSMutableDictionary *actions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"bounds", [NSNull null], @"position", nil]; </code></pre> <p>and this seems to work. Then I've overridden the actionForKey: method in my layer subclass</p> <pre><code>- (id&lt;CAAction&gt;)actionForKey:(NSString *)event { if ([event isEqualToString:@"frame.size.height"]) { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"frame.size.height"]; [animation setDuration:0.5f]; return animation; } return nil; } </code></pre> <p>but then when I change the height of my layer with</p> <pre><code>[layer setValue:[NSNumber numberForFloat:50.0] forKey:@"frame.size.height"]; </code></pre> <p>the height changes but is not animated. I see the actionForKey: method being called with frame.size.height but no matter what I return it is never animated. The height animates correctly if I don't set the actions, or have the actionForKey: method, but then the window resizes are also animated, which I don't want.</p> <p>Also, maybe I'm misunderstanding, but I thought returning nil from actionForKey: would make the default animations run, but it appears that even the presence of the method stops all implicit animations (whether the actions dictionary is set or not). </p> <p>What is it am I missing here, I'll be grateful for any pointers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload