Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
Binary file not shown.
@@ -0,0 +1,42 @@
//
// LXWaveProgressView.h
// LXWaveProgressDemo
//
// Created by liuxin on 16/8/1.
// Copyright © 2016年 liuxin. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LXWaveProgressView : UIView
/**
* 进度 0-1
*/
@property (nonatomic,assign)CGFloat progress;
/**
* 波动速度,默认 1
*/
@property (nonatomic,assign)CGFloat speed;
/**
* 波纹填充颜色
*/
@property (nonatomic,strong)UIColor * firstWaveColor;
@property (nonatomic,strong)UIColor * secondWaveColor;
/**
* 波动幅度,默认 5
*/
@property (nonatomic,assign)CGFloat waveHeight;
/**
* 进度文字
*/
@property (nonatomic,strong)UILabel * progressLabel;
/**
* 是否显示单层波浪,默认NO
*/
@property (nonatomic,assign)BOOL isShowSingleWave;
@end
@@ -0,0 +1,215 @@
//
// LXWaveProgressView.m
// LXWaveProgressDemo
//
// Created by liuxin on 16/8/1.
// Copyright © 2016年 liuxin. All rights reserved.
//
#define LXDefaultFirstWaveColor [UIColor colorWithRed:111/255.0 green:200/255.0 blue:255/255.0 alpha:0.5]
#define LXDefaultSecondWaveColor [UIColor colorWithRed:72/255.0 green:174/255.0 blue:236/255.0 alpha:1]
//#define LXDefaultSecondWaveColor [UIColor colorWithRed:207/255.0 green:237/255.0 blue:255/255.0 alpha:1]
#import "LXWaveProgressView.h"
#import "YYWeakProxy.h"
@interface LXWaveProgressView ()
@property (nonatomic,assign)CGFloat yHeight;
@property (nonatomic,assign)CGFloat offset;
@property (nonatomic,strong)CADisplayLink * timer;
@property (nonatomic,strong)CAShapeLayer * firstWaveLayer;
@property (nonatomic,strong)CAShapeLayer * secondWaveLayer;
@end
@implementation LXWaveProgressView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
//打开可设置圆形边框
//self.bounds = CGRectMake(0, 0, MIN(frame.size.width, frame.size.height), MIN(frame.size.width, frame.size.height));
//self.layer.cornerRadius = MIN(frame.size.width, frame.size.height) * 0.5;
self.bounds = CGRectMake(0, 0, MAX(frame.size.width, frame.size.height), MIN(frame.size.width, frame.size.height));
//打开可设置边框
// self.layer.masksToBounds = YES;
// self.layer.borderColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:248/255.0 alpha:1].CGColor;
// self.layer.borderWidth = 5.0f;
self.waveHeight = 5.0;
self.firstWaveColor = LXDefaultFirstWaveColor;
self.secondWaveColor = LXDefaultSecondWaveColor;
self.yHeight = self.bounds.size.height;
self.speed=2.0;
self.progress = 0.6;
[self.layer addSublayer:self.firstWaveLayer];
if (!self.isShowSingleWave) {
[self.layer addSublayer:self.secondWaveLayer];
}
[self addSubview:self.progressLabel];
self.progressLabel.hidden = YES;
}
return self;
}
-(void)awakeFromNib{
[super awakeFromNib];
self.waveHeight = 5.0;
self.firstWaveColor = LXDefaultFirstWaveColor;
self.secondWaveColor = LXDefaultSecondWaveColor;
self.yHeight = self.bounds.size.height;
self.speed=2.0;
self.progress = 0.6;
[self.layer addSublayer:self.firstWaveLayer];
if (!self.isShowSingleWave) {
[self.layer addSublayer:self.secondWaveLayer];
}
[self addSubview:self.progressLabel];
self.progressLabel.hidden = YES;
}
-(void)setProgress:(CGFloat)progress
{
_progress = progress;
_progressLabel.text = [NSString stringWithFormat:@"%ld%%",(long)[[NSNumber numberWithFloat:progress * 100] integerValue]];
_progressLabel.textColor=[UIColor colorWithWhite:progress*1.8 alpha:1];
self.yHeight = self.bounds.size.height * (1 - progress);
[self stopWaveAnimation];
[self startWaveAnimation];
}
#pragma mark -- 开始波动动画
- (void)startWaveAnimation
{
self.timer = [CADisplayLink displayLinkWithTarget:[YYWeakProxy proxyWithTarget:self] selector:@selector(waveAnimation)];
[self.timer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
#pragma mark -- 停止波动动画
- (void)stopWaveAnimation
{
[self.timer invalidate];
self.timer = nil;
}
#pragma mark -- 波动动画实现
- (void)waveAnimation
{
CGFloat waveHeight = self.waveHeight;
if (self.progress == 0.0f || self.progress == 1.0f) {
waveHeight = 0.f;
}
self.offset += self.speed;
//第一个波纹
CGMutablePathRef pathRef = CGPathCreateMutable();
CGFloat startOffY = waveHeight * sinf(self.offset * M_PI * 2 / self.bounds.size.width);
CGFloat orignOffY = 0.0;
CGPathMoveToPoint(pathRef, NULL, 0, startOffY);
for (CGFloat i = 0.f; i <= self.bounds.size.width; i++) {
orignOffY = waveHeight * sinf(2 * M_PI / self.bounds.size.width * i + self.offset * M_PI * 2 / self.bounds.size.width) + self.yHeight;
CGPathAddLineToPoint(pathRef, NULL, i, orignOffY);
}
CGPathAddLineToPoint(pathRef, NULL, self.bounds.size.width, orignOffY);
CGPathAddLineToPoint(pathRef, NULL, self.bounds.size.width, self.bounds.size.height);
CGPathAddLineToPoint(pathRef, NULL, 0, self.bounds.size.height);
CGPathAddLineToPoint(pathRef, NULL, 0, startOffY);
CGPathCloseSubpath(pathRef);
self.firstWaveLayer.path = pathRef;
self.firstWaveLayer.fillColor = self.firstWaveColor.CGColor;
CGPathRelease(pathRef);
//第二个波纹
if (!self.isShowSingleWave) {
CGMutablePathRef pathRef1 = CGPathCreateMutable();
CGFloat startOffY1 = waveHeight * sinf(self.offset * M_PI * 2 / self.bounds.size.width);
CGFloat orignOffY1 = 0.0;
CGPathMoveToPoint(pathRef1, NULL, 0, startOffY1);
for (CGFloat i = 0.f; i <= self.bounds.size.width; i++) {
orignOffY1 = waveHeight * 1.6 * cosf(2 * M_PI / self.bounds.size.width * i + self.offset * M_PI * 2 / self.bounds.size.width) + self.yHeight;
CGPathAddLineToPoint(pathRef1, NULL, i, orignOffY1);
}
CGPathAddLineToPoint(pathRef1, NULL, self.bounds.size.width, orignOffY1);
CGPathAddLineToPoint(pathRef1, NULL, self.bounds.size.width, self.bounds.size.height);
CGPathAddLineToPoint(pathRef1, NULL, 0, self.bounds.size.height);
CGPathAddLineToPoint(pathRef1, NULL, 0, startOffY1);
CGPathCloseSubpath(pathRef1);
self.secondWaveLayer.path = pathRef1;
self.secondWaveLayer.fillColor = self.secondWaveColor.CGColor;
CGPathRelease(pathRef1);
}
}
#pragma mark ----- INITUI ----
-(CAShapeLayer *)firstWaveLayer{
if (!_firstWaveLayer) {
_firstWaveLayer = [CAShapeLayer layer];
_firstWaveLayer.frame = self.bounds;
_firstWaveLayer.fillColor = _firstWaveColor.CGColor;
}
return _firstWaveLayer;
}
-(CAShapeLayer *)secondWaveLayer{
if (!_secondWaveLayer) {
_secondWaveLayer = [CAShapeLayer layer];
_secondWaveLayer.frame = self.bounds;
_secondWaveLayer.fillColor = _secondWaveColor.CGColor;
}
return _secondWaveLayer;
}
-(UILabel *)progressLabel{
if (!_progressLabel) {
_progressLabel=[[UILabel alloc] init];
_progressLabel.text=@"0%";
_progressLabel.frame=CGRectMake(0, 0, self.bounds.size.width, 30);
_progressLabel.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
_progressLabel.font=[UIFont systemFontOfSize:20];
_progressLabel.textColor=[UIColor colorWithWhite:0 alpha:1];
_progressLabel.textAlignment=1;
}
return _progressLabel;
}
-(void)dealloc{
[self.timer invalidate];
self.timer = nil;
if (_firstWaveLayer) {
[_firstWaveLayer removeFromSuperlayer];
_firstWaveLayer = nil;
}
if (_secondWaveLayer) {
[_secondWaveLayer removeFromSuperlayer];
_secondWaveLayer = nil;
}
}
@end
@@ -0,0 +1,61 @@
//
// YYWeakProxy.h
// YYKit <https://github.com/ibireme/YYKit>
//
// Created by ibireme on 14/10/18.
// Copyright (c) 2015 ibireme.
//
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
A proxy used to hold a weak object.
It can be used to avoid retain cycles, such as the target in NSTimer or CADisplayLink.
sample code:
@implementation MyView {
NSTimer *_timer;
}
- (void)initTimer {
YYWeakProxy *proxy = [YYWeakProxy proxyWithTarget:self];
_timer = [NSTimer timerWithTimeInterval:0.1 target:proxy selector:@selector(tick:) userInfo:nil repeats:YES];
}
- (void)tick:(NSTimer *)timer {...}
@end
*/
@interface YYWeakProxy : NSProxy
/**
The proxy target.
*/
@property (nullable, nonatomic, weak, readonly) id target;
/**
Creates a new weak proxy for target.
@param target Target object.
@return A new proxy object.
*/
- (instancetype)initWithTarget:(id)target;
/**
Creates a new weak proxy for target.
@param target Target object.
@return A new proxy object.
*/
+ (instancetype)proxyWithTarget:(id)target;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,83 @@
//
// YYWeakProxy.m
// YYKit <https://github.com/ibireme/YYKit>
//
// Created by ibireme on 14/10/18.
// Copyright (c) 2015 ibireme.
//
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "YYWeakProxy.h"
@implementation YYWeakProxy
- (instancetype)initWithTarget:(id)target {
_target = target;
return self;
}
+ (instancetype)proxyWithTarget:(id)target {
return [[YYWeakProxy alloc] initWithTarget:target];
}
- (id)forwardingTargetForSelector:(SEL)selector {
return _target;
}
- (void)forwardInvocation:(NSInvocation *)invocation {
void *null = NULL;
[invocation setReturnValue:&null];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
return [NSObject instanceMethodSignatureForSelector:@selector(init)];
}
- (BOOL)respondsToSelector:(SEL)aSelector {
return [_target respondsToSelector:aSelector];
}
- (BOOL)isEqual:(id)object {
return [_target isEqual:object];
}
- (NSUInteger)hash {
return [_target hash];
}
- (Class)superclass {
return [_target superclass];
}
- (Class)class {
return [_target class];
}
- (BOOL)isKindOfClass:(Class)aClass {
return [_target isKindOfClass:aClass];
}
- (BOOL)isMemberOfClass:(Class)aClass {
return [_target isMemberOfClass:aClass];
}
- (BOOL)conformsToProtocol:(Protocol *)aProtocol {
return [_target conformsToProtocol:aProtocol];
}
- (BOOL)isProxy {
return YES;
}
- (NSString *)description {
return [_target description];
}
- (NSString *)debugDescription {
return [_target debugDescription];
}
@end