iOS實(shí)現(xiàn)手指點(diǎn)擊出現(xiàn)波紋的效果
實(shí)現(xiàn)來看看模擬器上效果:
具體的實(shí)現(xiàn)代碼如下
首先監(jiān)聽控制器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
總結(jié)
大家也可以DIY我的代碼,做出很多其他的效果,比如改成其他的波紋顏色。以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容ui各位iOS開發(fā)者們能有所幫助,如果有疑問大家可以留言交流。
- IOS 波紋進(jìn)度(waveProgress)動畫實(shí)現(xiàn)
- iOS實(shí)現(xiàn)百度外賣頭像波浪的效果
- IOS中實(shí)現(xiàn)圖片點(diǎn)擊全屏預(yù)覽
- iOS開發(fā)中使用UIScrollView實(shí)現(xiàn)圖片輪播和點(diǎn)擊加載
- 詳解iOS中Button按鈕的狀態(tài)和點(diǎn)擊事件
- ios通過按鈕點(diǎn)擊異步加載圖片
- IOS開發(fā)之tableView點(diǎn)擊行跳轉(zhuǎn)并帶有“顯示”更多功能
- iOS實(shí)現(xiàn)點(diǎn)擊狀態(tài)欄自動回到頂部效果詳解
- IOS實(shí)現(xiàn)點(diǎn)擊滑動抽屜效果
- iOS點(diǎn)擊文字按鈕變轉(zhuǎn)圈加載效果
相關(guān)文章
ios動態(tài)設(shè)置lbl文字標(biāo)簽的高度
本文給大家分享的是ios動態(tài)設(shè)置lbl文字標(biāo)簽的高度寬度的方法,一共給大家匯總了3種方法,小伙伴們根據(jù)自己的項(xiàng)目需求自由選擇。2015-05-05iOS 隱私權(quán)限和通過openURL實(shí)現(xiàn)跳轉(zhuǎn)實(shí)例
這篇文章主要介紹了iOS 隱私權(quán)限和通過openURL實(shí)現(xiàn)跳轉(zhuǎn)實(shí)例,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06詳解iOS應(yīng)用程序內(nèi)購/內(nèi)付費(fèi)(一)
這篇文章主要介紹了詳解iOS應(yīng)用程序內(nèi)購/內(nèi)付費(fèi)(一),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。2016-12-12