【问题标题】:Issue animating with CATransform3DRotate使用 CATransform3DRotate 制作动画问题
【发布时间】:2015-11-24 07:45:12
【问题描述】:

我的代码如下,但动画只是立即发生,即视图不再可见:

UIView *leftDoorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width /2, self.view.bounds.size.height)];      
leftDoorView.backgroundColor = [UIColor greenColor];
leftDoorView.layer.anchorPoint = CGPointMake(0.0, 0.5);
[self.view addSubview:leftDoorView];

leftDoorView.center = CGPointMake(0.0, self.view.bounds.size.height/2.0); //compensate for anchor offset

CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1.0f/500.0;
transform = CATransform3DRotate(transform, M_PI_2, 0, 1, 0);

[UIView animateWithDuration:1.0 animations:^{

        leftDoorView.layer.transform = transform;
 }];

不确定我做错了什么 - 请提供任何帮助。

【问题讨论】:

  • 我刚刚将您的代码复制到应用程序的 viewDidAppear: 中,它可以正确显示动画。

标签: ios core-graphics core-animation


【解决方案1】:

问题原来是其他视图层的 zPositions - 很可能是由视图层次结构中的 UITableView 引起的。

设置是一个 UIViewController,它在 viewDidLoad 中向它自己的视图添加一个 header UIImageView 和一个 UITableView。然后将动画最后添加到其他视图之上。似乎 UITableView 以某种方式修改了层的 zPositions,所以只有在最终尝试 leftdoorView.layer.zPosition = 1000; 并将实际动画移动到单独的选择器后,在 viewDidLoad 后 0.2 秒执行动画才能正确显示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多