设置锚定点时

时间:2018-08-07 12:21:40

标签: ios core-animation catransform3d

当我为其他子视图B制作CATransform3DRotate动画时,顶层子视图A被覆盖。子视图A和子视图B都具有相同的超级视图。我将子视图B层锚点设置为CGPointMake(0.5, 0),以使子视图B可以沿X轴旋转,但是为什么子视图A被覆盖是顶层。 还有我的代码。

- (void)addAnimation {
  [self setAnchorPoint:CGPointMake(0.5, 0) forView:self.shareView];
  CATransform3D first_transform = CATransform3DIdentity;
  first_transform.m34 = -1.0 / 500;
  first_transform = CATransform3DRotate(first_transform, 80 / 180.f, 1, 0, 0);

  [UIView animateWithDuration:0.6
                        delay:0
       usingSpringWithDamping:0.5
        initialSpringVelocity:0
                      options:UIViewAnimationOptionOverrideInheritedCurve
                   animations:^{
                     self.shareView.layer.transform = first_transform;
                   } completion:^(BOOL finished) {
                     [UIView animateWithDuration:0.4 animations:^{
                       self.shareView.layer.transform = CATransform3DIdentity;
                     }];
                   }];
}

- (void) setAnchorPoint:(CGPoint)anchorpoint forView:(UIView *)view{
  CGRect oldFrame = view.frame;
  view.layer.anchorPoint = anchorpoint;
  view.frame = oldFrame;
}

0 个答案:

没有答案