Note that there are some explanatory texts on larger screens.

plurals
  1. POCALayer transform is wrong after going back to the screen
    primarykey
    data
    text
    <p>I have a UIView to which I'm applying a CAAnimation. <em>animation</em> is an instance of a class that inherits from CAKeyframeAnimation, which keypath is @"transform.scale".</p> <pre><code>[[myView layer] addAnimation:animation forKey:@"animation key"]; [[myView layer] setValue:[NSNumber numberWithBool:finalScale] forKey:@"transform.scale"]; </code></pre> <p>As usual, besides adding the animation I'm setting the value so that when it's over, it doesn't go back to the original state.</p> <p>This all works nicely. However, if I exit this controller and then go back, somehow that layer has this transform applied twice, so it looks 4 times smaller, even though the current value is <em>finalScale</em>.</p> <p>I've tried saving the current transform on viewWillDisappear and apply that again on viewWillAppear. Also tried this on viewWillAppear:</p> <pre><code>[myView.layer setTransform:CATransform3DIdentity]; </code></pre> <p>But none of those worked. It looks like there is some other matrix calculation being made under the hood, or am I missing something?</p> <p>EDIT: This is how I'm creating the animation:</p> <pre><code>double startValue = [[view.layer.presentationLayer valueForKeyPath:@"transform.scale"] doubleValue]; ExponentialAnimation *animation = [ExponentialAnimation animationWithKeyPath:@"transform.scale" startValue:startValue endValue:endValue duration:kDuration]; [view.layer removeAnimationForKey:@"scale"]; [view.layer addAnimation:animation forKey:@"scale"]; [view.layer setValue:[NSNumber numberWithFloat:endValue] forKeyPath:@"transform.scale"]; </code></pre> <p>ExponentialAnimation looks like this:</p> <pre><code>@interface ExponentialAnimation : CAKeyframeAnimation { double _startValue; double _endValue; NSUInteger _steps; } @implementation ExponentialAnimation @synthesize startValue=_startValue, endValue=_endValue; + (id)animationWithKeyPath:(NSString *)keyPath startValue:(double)startValue endValue:(double)endValue duration:(CGFloat)duration { return [[[self alloc] initWithKeyPath:keyPath startValue:startValue endValue:endValue duration:duration] autorelease]; } - (id)initWithKeyPath:(NSString *)keyPath startValue:(double)start endValue:(double)end duration:(CGFloat)duration { if ((self = [super init])) { self.keyPath = keyPath; self.duration = duration; _startValue = start; _endValue = end; _steps = [self numberOfStepsForDuration:duration withFPS:kAnimationFPS]; [self calculateKeyFrames]; } return self; } </code></pre> <p>calculateSteps just creates an array of values for every keyframe and adds it like:</p> <pre><code>[self setValues:values]; </code></pre> <p>When the viewController disappears, <em>view</em> has scale set to 0.4 (<em>endValue</em> in the animation). When I go back, getting the value of [view.layer valueForKeyPath:@"transform.scale"] gives 0.4, but what you really see is something like 0.4 * 0.4.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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