1

我有一个CircleView : UIView类,当你触摸它时(通过pop函数)动画(收缩和增长)。当你触摸它时,我还希望一个描边的圆圈出现并长出来(就像一个基本的水波纹)。(我说的效果在这里用 CSS展示)

我该怎么做呢?

更多信息:

  • 理想情况下,两个动画都可以从单个CircleView类中控制
  • CircleView继承关闭UIView

更新

根据答案,我通过 a 添加了一个新对象subLayer。这显示正常,但在pop. 谁能帮我理解为什么?

这是我当前的代码(无论如何相关的位)

- (void)layoutSubviews
{
    [self setLayerProperties];
}

- (void)setLayerProperties {
//The view’s Core Animation layer used for rendering.
CAShapeLayer *layer = (CAShapeLayer *)self.layer;

UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)
                                                  byRoundingCorners:UIRectCornerAllCorners
                                                        cornerRadii:self.frame.size];
layer.path = bezierPath.CGPath;
layer.fillColor = _Color.CGColor;

rippleLayer = [[CALayer alloc] init];
layer.path = bezierPath.CGPath;
layer.strokeColor = [UIColor blueColor].CGColor;
[layer addSublayer:rippleLayer];
}

// Does the animated "pop"
- (void)pop{

    CABasicAnimation *animation = [self animationWithKeyPath:@"transform.scale"];
    [animation setFromValue:[NSNumber numberWithFloat:1.0f]];
    [animation setToValue:[NSNumber numberWithFloat:0.8f]];
    [animation setRemovedOnCompletion:YES];
    [animation setDuration:0.15];
    [animation setAutoreverses:YES];

    [self.layer addAnimation:animation forKey:animation.keyPath];

    rippleLayer.anchorPoint = CGPointMake(1, 1);
    CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    [scale setFromValue:[NSNumber numberWithFloat:1.0f]];
    [scale setToValue:[NSNumber numberWithFloat:2.0f]];
    [scale setRepeatCount:1];
    [scale setDuration:1.0f];
    //r[scale setRemovedOnCompletion:YES];
    [scale setFillMode:kCAFillModeForwards];

    [rippleLayer addAnimation:scale forKey:scale.keyPath];
}
4

1 回答 1

0

只需将要设置动画的其他对象添加到图层并将其 alpha 设置为 0.0。然后,您可以在动画中或动画之前使用该值。

我注意到您没有遵循使用小首字母命名变量的约定。_color会比_Color.

此外,如果您想将图层置于其原始状态,您通常使用识别变换矩阵:

self.transform = CGAffineTransformIdentity;
于 2013-11-10T18:29:10.207 回答