带旋转动画的CALayer [英] CALayer with rotation animation

查看:107
本文介绍了带旋转动画的CALayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我屏蔽了这样的图像:

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,旋转动画视图或图层(我不是很确定)不起作用。它旋转没有动画。你能帮帮忙吗?

It works fine but the main problem is if I want to rotate the my Ipad, the rotation animation of the view or the layer (I'm not very sure) doesn't work. It rotates without animation. Could you help, please?

推荐答案

旋转 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 应该是弧度。逆时针旋转使用负值,顺时针使用正值。

myRotationAngle should be in radians. Use negative values for counter-clockwise rotation and positive values for clockwise.

这篇关于带旋转动画的CALayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆