自定义一个类,继承与UIButton。
-(void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event{
[super sendAction:action to:target forEvent:event];
//按钮点击时的效果
CAShapeLayer * layer = [[CAShapeLayer alloc]init];
layer.frame = self.bounds;
layer.strokeColor = [UIColor clearColor].CGColor;
layer.fillColor = [[UIColor blackColor] colorWithAlphaComponent:0.1].CGColor;
[self.layer addSublayer:layer];
UIBezierPath * pathStart = [UIBezierPath bezierPath];
pathStart = [UIBezierPath bezierPathWithOvalInRect:self.bounds]; //椭圆形,如果是rect是正方形,则是圆形。
UIBezierPath * pathEnd = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.bounds, -5, -5)];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.delegate = self;
animation.fromValue = (__bridge id)pathStart.CGPath;
animation.toValue = (__bridge id)pathEnd.CGPath;
animation.duration = 0.25f;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[layer addAnimation:animation forKey:@"path"];
}
网友评论