国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS實現手指點擊出現波紋的效果

2020-07-26 03:03:17
字體:
來源:轉載
供稿:網友

實現來看看模擬器上效果:

具體的實現代碼如下

首先監聽控制器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 <UIKit/UIKit.h>@interface FingerWaveView : UIView+ (instancetype)showInView:(UIView *)view center:(CGPoint)center;@end

FingerWaveView.m

#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

總結

大家也可以DIY我的代碼,做出很多其他的效果,比如改成其他的波紋顏色。以上就是這篇文章的全部內容了,希望本文的內容ui各位iOS開發者們能有所幫助,如果有疑問大家可以留言交流。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 枝江市| 普宁市| 龙江县| 大竹县| 绥江县| 津南区| 丁青县| 沧源| 洛南县| 乃东县| 增城市| 钟祥市| 南安市| 池州市| 万载县| 武平县| 新干县| 河南省| 舞钢市| 香港 | 库车县| 封丘县| 昌都县| 翁源县| 平和县| 华容县| 合川市| 南投县| 凌云县| 阿克苏市| 广元市| 尼勒克县| 田东县| 章丘市| 绥芬河市| 扶余县| 阳高县| 临洮县| 磐安县| 九龙坡区| 精河县|