gpt4 book ai didi

iphone - 带有旋转动画的 CALayer

转载 作者:技术小花猫 更新时间:2023-10-29 10:50:12 26 4
gpt4 key购买 nike

我屏蔽了这样一张图片:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com