animation之后,我的CALayer变换保持不变,但视angular消失
我有下面的代码,在Y轴上旋转CALayer -45degrees:
#define D2R(x) (x * (M_PI/180.0)) - (void) swipe:(UISwipeGestureRecognizer *)recognizer { CATransform3D transform = CATransform3DMakeRotation(D2R(-45), 0, 1.0, 0); transform.m34 = -1.0 / 850; CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"]; transformAnimation.fillMode = kCAFillModeForwards; transformAnimation.removedOnCompletion = NO; transformAnimation.toValue = [NSValue valueWithCATransform3D:transform]; transformAnimation.duration = 0.5; [self.layer addAnimation:transformAnimation forKey:@"transform"]; }
animation的作品,除了没有视angular结束 – 忽略了我的m34设置,如果我正确地理解的东西。
中途:
最后:
我究竟做错了什么?
animation仅在animation期间影响视图的外观。 animation结束后,它不会应用于视图。 你需要自己做这个。 在添加animation之后,我正在猜测这样的事情:
self.layer.transform = transform;
您可以立即执行此操作,因为animation会在animation完成之前隐藏它。
尝试这个 :
- (void) swipe:(UISwipeGestureRecognizer *)recognizer { CATransform3D transform = CATransform3DIdentity; transform.m34 = -10 / 850.0; transform = CATransform3DRotate(transform, D2R(-45), 0, 1.0, 0); CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"]; transformAnimation.fillMode = kCAFillModeForwards; transformAnimation.removedOnCompletion = NO; transformAnimation.toValue = [NSValue valueWithCATransform3D:transform]; transformAnimation.duration = 0.5; [self.layer addAnimation:transformAnimation forKey:@"transform"]; }
结束效果是这样的: