Note that there are some explanatory texts on larger screens.

plurals
  1. POCALayer transform different when animated
    text
    copied!<p>This has been driving me crazy. I am using s <code>CATransform3D</code> to animate the main layer of my view (to apply a perspective effect). I have a function called <code>ApplyPerspective</code> that sets it up, and <code>ClearPerspective</code> which resets the layer's transform property to <code>CATransform3DIdentity</code>.</p> <p>Here's my code:</p> <pre><code> ApplyPerspective(self.mainContentView); [UIView animateWithDuration:self.animationDuration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ ClearPerspective(self.mainContentView); } completion:nil]; </code></pre> <p>The issue I am having is that the perspective transform applied by <code>ApplyPerspective</code> is incorrect. If I remove the -<code>animateWithDuration</code> call, but leave the <code>ApplyPerspective</code> call, the layer is rendered as expected. I am not sure why the behavior is changing when animated.</p> <p>I have tried changing the duration, animation curve, flattening the function calls, but I am unable to trace the source of this error.</p> <p>Update to add bodies of ApplyPerspective() and ClearPerspective():</p> <pre><code>void ApplyPerspective(UIView *aView) { // Magic numbers derived using debug sliders CGFloat zDist, rotRads, xOffset, yOffset, scale, shift; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { zDist = 172.5378; rotRads = 2.6531; xOffset = -13.0; yOffset = 402; shift = -241; } else { zDist = 513.4995; rotRads = 1.0007; xOffset = 0.0; yOffset = -100.0; scale = 1.0; shift = 0.0; } CATransform3D p = CATransform3DIdentity; p = CATransform3DTranslate(p, xOffset, yOffset, 0.0); p.m34 = 1.0 / -zDist; p = CATransform3DRotate(p, rotRads, 1.0, 0.0, 0); p = CATransform3DTranslate(p, 0, shift, 0.0); aView.layer.transform = p; } void ClearPerspective(UIView *aView, UIView *parentView) { aView.layer.transform = CATransform3DIdentity; } </code></pre> <p>Here's the view hierarchy: mainContentView is a child of the ViewController's root view, which uses auto layout. The constraints are such that mainContentView fills the root view. mainContentView has a sibling image view which is used as a background during the animation.</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