我的代码如下所示,但是动画就会立即发生--也就是说,视图不再可见:
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;
}];不知道我做错了什么-任何帮助都将不胜感激。
发布于 2015-11-26 10:55:39
这个问题最终被证明是其他视图层的zPositions --很可能是由视图层次结构中的UITableView引起的。
设置是一个UIViewController,它在viewDidLoad中向自己的视图中添加了一个标头UIImageView和一个UITableView。然后将动画添加到其他视图之上。UITableView似乎以某种方式修改了图层的zPositions,所以只有在最终尝试了leftdoorView.layer.zPosition = 1000;并将实际的动画移动到一个单独的选择器之后,viewDidLoad才执行了0.2秒的动画显示。
https://stackoverflow.com/questions/33887975
复制相似问题