我掩盖了这样的图像:
UIView *maskImage; maskImage = [[UIView alloc] init];
maskImage.backgroundColor = UIColorFromRGB(FTRMaskColor);
maskImage.frame = newFrame;
CALayer *theLayer = [CALayer layer];
theLayer.contents = (id)[[UIImage imageNamed:@"image.png"] CGImage];
theLayer.frame = newFrame;
maskImage.layer.mask = theLayer;
它工作正常,但主要问题是如果我想旋转我的Ipad,视图或图层的旋转动画(我不是很确定)不起作用。它旋转没有动画。你能帮忙吗?
旋转一个 CALayer
:
NSNumber *rotationAtStart = [myLayer valueForKeyPath:@"transform.rotation"];
CATransform3D myRotationTransform = CATransform3DRotate(myLayer.transform, myRotationAngle, 0.0, 0.0, 1.0);
myLayer.transform = myRotationTransform;
CABasicAnimation *myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
myAnimation.duration = kMyAnimationDuration;
myAnimation.fromValue = rotationAtStart;
myAnimation.toValue = [NSNumber numberWithFloat:([rotationAtStart floatValue] + myRotationAngle)];
[myLayer addAnimation:myAnimation forKey:@"transform.rotation"];
myRotationAngle
应该是弧度。逆时针旋转使用负值,顺时针使用正值。
CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation];
rotation.keyPath = @"transform.rotation";
rotation.values = @[ @0.14, @0,@0.2 ,@0];
rotation.timingFunctions = @[
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
];
rotation.fillMode = kCAFillModeForwards;
rotation.removedOnCompletion = NO;
rotation.beginTime = AVCoreAnimationBeginTimeAtZero;
[imageLayer addAnimation:rotation forKey:@"rotation"];