波纹效果在IOS开发中的实现步骤

来源:爱站网时间:2021-01-25编辑:网友分享
在项目开发的时候我们通常要让项目达到一定的效果,会制作出一些意象不到的操作,爱站技术频道小编今天就为大家带来了波纹效果在IOS开发中的实现步骤,感兴趣的朋友们下面来一起看看吧。

在项目开发的时候我们通常要让项目达到一定的效果,会制作出一些意象不到的操作,爱站技术频道小编今天就为大家带来了波纹效果在IOS开发中的实现步骤,感兴趣的朋友们下面来一起看看吧。

实现来看看模拟器上效果:

具体的实现代码如下

首先监听控制器view的Tap事件

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];
}

FingerWaveView.h

#import 
@interface FingerWaveView : UIView
+ (instancetype)showInView:(UIView *)view center:(CGPoint)center;
@end

FingerWaveView.m

#import "FingerWaveView.h"
@interface FingerWaveView () 
{
 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

上述是爱站技术频道小编为大家带来的波纹效果在IOS开发中的实现步骤,希望能为你提供帮助和参考,让你在学习中狩猎更多的知识。

上一篇:IOS开发中发送验证码倒计时的实现操作

下一篇:ios如何利用AFN上传相册或者拍照图片

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载