我在UIImageView(图像上的对象)有一个UIImage。它需要动画到右侧,但是这个动画需要用这个圆圈蒙版来掩盖。 动画UIImageView与面具(核心动画与面具)
我当前的代码是:
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, 44, 44, 21, 0, 2 * M_PI, NO);
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
[shapeLayer setPath:path];
[shapeLayer setFillColor:[[UIColor blackColor] CGColor]];
[shapeLayer setBounds:CGRectMake(0, 0, 44, 44)];
[shapeLayer setPosition:CGPointMake(0, 0)];
UIImageView *loadingShape = [[UIImageView alloc] initWithFrame:CGRectMake(6.5, 7.5, 89, 40)];
[loadingShape setImage:[UIImage imageNamed:@"object_image.png"]];
[self addSubview:loadingShape];
// Set the mask for the image view's layer
[[loadingShape layer] setMask:shapeLayer];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.3];
[UIView setAnimationRepeatCount:10];
[loadingShape setFrame:CGRectMake(0, 7.5, 89, 40)];
[UIView commitAnimations];
但这动画我的整个的UIImageView掩盖。我需要面具是静态的,只是在物体背后被动画。
什么是最好的解决方案呢?
你正在动画'position',但是给它'fromValue'和'toValue'这是'CGRect's。他们不应该成为'CGPoints'吗? – 2012-03-23 18:25:16
你是对的,我改变了代码。但这两种解决方案的工作 – dormitkon 2012-03-23 18:49:45