@implementation UIView (****)
- (void)3dBackgroundAnimation:(BOOL)show duration:(CGFloat)duration
{
if (show) {
CGFloat x = self.center.x;
CGFloat y = self.frame.origin.y;
self.layer.anchorPoint = CGPointMake(0.5, 0);
self.layer.position = CGPointMake(x, y);
//起始值
CATransform3D fromValue = CATransform3DIdentity;
fromValue.m34 = -1.f / 300;
fromValue = CATransform3DRotate(fromValue, 0, 1, 0, 0);
// 结束值
CATransform3D toValue = CATransform3DIdentity;
toValue.m34 = -1.f / 300;
toValue = CATransform3DRotate(toValue, 25.f, 1, 0, 0);
// 添加3D动画
CABasicAnimation *transform3D = [CABasicAnimation animationWithKeyPath:@"transform"];
transform3D.duration = duration;
transform3D.fromValue = [NSValue valueWithCATransform3D:fromValue];
transform3D.toValue = [NSValue valueWithCATransform3D:toValue];
self.layer.transform = toValue;
[self.layer addAnimation:transform3D forKey:@"transform3D"];
}
else {
CABasicAnimation *transform3D = [CABasicAnimation animationWithKeyPath:@"transform"];
transform3D.duration = duration;
CATransform3D toValue = CATransform3DIdentity;
toValue = CATransform3DRotate(toValue, 0, 1, 0, 0);
self.layer.transform = toValue;
[self.layer addAnimation:transform3D forKey:@"transform3D"];
}
}
@end
3D旋转动画
最新推荐文章于 2024-04-09 13:07:53 发布