我屏蔽了这样一张图片:
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, View 或层的旋转动画(我不太确定)不起作用。它在没有动画的情况下旋转。你能帮忙吗?
最佳答案
旋转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
应该以弧度为单位。逆时针旋转使用负值,顺时针旋转使用正值。
关于iphone - 带有旋转动画的 CALayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6690780/