UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)]; [self.view addGestureRecognizer:tap];
- (void)onTap:(UITapGestureRecognizer*)sender {
CGPoint center = [sender locationInView:sender.view];
[FingerWaveView showInView:self.view center:center];
}
#import <UIKit/UIKit.h> @interface FingerWaveView : UIView + (instancetype)showInView:(UIView *)view center:(CGPoint)center; @end
#import "FingerWaveView.h"
@interface FingerWaveView () <CAAnimationDelegate>
{
CGSize waveSize;
NSTimeInterval duration;
}
@end
@implementation FingerWaveView
- (instancetype)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
waveSize = CGSizeMake(150, 150);
duration = 1.0;
}
return self;
}
+ (instancetype)showInView:(UIView *)view center:(CGPoint)center {
FingerWaveView *waveView = [FingerWaveView new];
[waveView setframeWithCenter:center];
[view addSubview:waveView];
return waveView;
}
- (void)didMoveToSuperview{
CAShapeLayer *waveLayer = [CAShapeLayer new];
waveLayer.backgroundColor = [UIColor clearColor].CGColor;
waveLayer.opacity = 0.6;
waveLayer.fillColor = [UIColor whiteColor].CGColor;
[self.layer addSublayer:waveLayer];
[self startAnimationInLayer:waveLayer];
}
- (void)startAnimationInLayer:(CALayer *)layer{
UIBezierPath *beginPath = [UIBezierPath bezierPathWithArcCenter:[self pathCenter] radius:[self animationBeginRadius] startAngle:0 endAngle:M_PI*2 clockwise:YES];
UIBezierPath *endPath = [UIBezierPath bezierPathWithArcCenter:[self pathCenter] radius:[self animationEndRadius] startAngle:0 endAngle:M_PI*2 clockwise:YES];
CABasicAnimation *rippleAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
rippleAnimation.delegate = self;
rippleAnimation.fromValue = (__bridge id _Nullable)(beginPath.CGPath);
rippleAnimation.toValue = (__bridge id _Nullable)(endPath.CGPath);
rippleAnimation.duration = duration;
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.delegate = self;
opacityAnimation.fromValue = [NSNumber numberWithFloat:0.6];
opacityAnimation.toValue = [NSNumber numberWithFloat:0.0];
opacityAnimation.duration = duration;
[layer addAnimation:rippleAnimation forKey:@"rippleAnimation"];
[layer addAnimation:opacityAnimation forKey:@"opacityAnimation"];
}
- (void)setframeWithCenter:(CGPoint)center{
CGRect frame = CGRectMake(center.x-waveSize.width*0.5, center.y-waveSize.height*0.5, waveSize.width, waveSize.height);
self.frame = frame;;
}
- (CGFloat)animationBeginRadius{
return waveSize.width*0.5*0.2;
}
- (CGFloat)animationEndRadius{
return waveSize.width*0.5;
}
- (CGPoint)pathCenter{
return CGPointMake(waveSize.width*0.5, waveSize.height*0.5);
}
#pragma mark - CAAnimationDelegate
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if (flag) {
[self removeFromSuperview];
}
}
@end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有