变换后CALayer与顶层重叠
我有两个 CALayer,每个显示一个图像。视图层次结构中的第一层(左)位于第二层之上。问题是,在我绕 y 轴旋转后,右侧图层突然绘制在本应位于顶部的图层上方。
我尝试使用不同的 zPosition 值。没有什么。我的另一个猜测是,右侧图层的动画可能在左侧图层的动画完成之后完成,因此它绘制在顶部。为了测试这一点,我首先对右侧图层应用了转换,但结果仍然相同。哦,我也尝试过CA交易,但没有成功。
这里有一个屏幕截图:
在保持多个 CALayers 的顺序的同时对它们进行动画处理的正确方法是什么?
谢谢,马克。 编辑:
这是转换的代码。我尝试禁用动画,但得到了相同的结果。
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / 400;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, DegreesToRadians(70), 0, 1, 0);
for(CALayer *layer in [self.layer sublayers]) {
// transform the two layers
layer.transform = rotationAndPerspectiveTransform;
}
[CATransaction commit];
I have two CALayers each showing an image. The first (left) layer in the view hierarchy is on top of the second one. The problem is that after I apply a rotation around the y-axis, the right layer is all of a sudden drawn above the layer that's supposed to be on top.
I tried using different zPosition values. Nothing. My other guess was that maybe the animation of the right layer finishes after the animation for the left layer and hence it is drawn on top. To test this, I applied the transformation for the right layer first, but still the same result. Oh, I also tried CA transactions without any luck.
Here a screenshot:
What is the correct way to animate a number of CALayers while keeping their order?
Thanks, Mark.
EDIT:
Here is the code for the transformation. I tried disabling the animation, but got the same result.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / 400;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, DegreesToRadians(70), 0, 1, 0);
for(CALayer *layer in [self.layer sublayers]) {
// transform the two layers
layer.transform = rotationAndPerspectiveTransform;
}
[CATransaction commit];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你试过在z轴上平移吗?要么让你的顶层有一个更大的数字,要么你的下层有一个更低的数字或负数。首先尝试一些非常大的东西,看看它是否可以解决问题。然后缩小边距,直到图层尽可能接近,而不会导致您看到的变化。像这样的事情:
缺点是,如果您计划堆叠一堆层,您可能必须使用这个最小边距并将其乘以您计划显示的层数,从而导致堆栈淡入距离。当然,如果这就是您想要的效果,那将是一件好事。
Have you tried translating on the z axis? Either make your top layer have a larger number or your lower layer have a lower or negative number. Try something really large to start with and see if it addresses the issue. Then narrow the margin until you get the layer as close as possible without causing the shift you're seeing. Something like this:
The down side is if you're planning to stack up a bunch of layers, you would probably have to use this minimum margin and multiply that by the number of layers you're planning to display causing the stack to fade into the distance. Of course, if that's the effect you're going for, this would be a good thing.