-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MJ
authored and
MJ
committed
Jul 23, 2016
1 parent
f5f746e
commit 71ab00e
Showing
5 changed files
with
528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# | ||
# Be sure to run `pod spec lint EBTWaterWaveView.podspec' to ensure this is a | ||
# valid spec and to remove all comments including this before submitting the spec. | ||
# | ||
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html | ||
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ | ||
# | ||
|
||
Pod::Spec.new do |s| | ||
|
||
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# These will help people to find your library, and whilst it | ||
# can feel like a chore to fill in it's definitely to your advantage. The | ||
# summary should be tweet-length, and the description more in depth. | ||
# | ||
|
||
s.name = "EBTWaterWaveView" | ||
s.version = "0.0.1" | ||
s.summary = "EBTWaterWaveView" | ||
|
||
# This description is used to generate tags and improve search results. | ||
# * Think: What does it do? Why did you write it? What is the focus? | ||
# * Try to keep it short, snappy and to the point. | ||
# * Write the description between the DESC delimiters below. | ||
# * Finally, don't worry about the indent, CocoaPods strips it! | ||
#s.description = <<-DESC | ||
# DESC | ||
s.homepage = "https://github.com/KBvsMJ/EBTWaterWaveDemo" | ||
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" | ||
|
||
|
||
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Licensing your code is important. See http://choosealicense.com for more info. | ||
# CocoaPods will detect a license file if there is a named LICENSE* | ||
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. | ||
# | ||
|
||
#s.license = "MIT (example)" | ||
# s.license = { :type => "MIT", :file => "FILE_LICENSE" } | ||
|
||
|
||
#――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Specify the authors of the library, with email addresses. Email addresses | ||
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also | ||
# accepts just a name if you'd rather not provide an email address. | ||
# | ||
# Specify a social_media_url where others can refer to, for example a twitter | ||
# profile URL. | ||
# | ||
|
||
s.author = { "kbvsmj" => "2455063164@qq.com" } | ||
#Or just: s.author = "KBvsMJ" | ||
# s.authors = { "" => "" } | ||
# s.social_media_url = "http://twitter.com/" | ||
|
||
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# If this Pod runs only on iOS or OS X, then specify the platform and | ||
# the deployment target. You can optionally include the target after the platform. | ||
# | ||
|
||
# s.platform = :ios | ||
s.platform = :ios, "8.0" | ||
|
||
# When using multiple platforms | ||
# s.ios.deployment_target = "5.0" | ||
# s.osx.deployment_target = "10.7" | ||
# s.watchos.deployment_target = "2.0" | ||
# s.tvos.deployment_target = "9.0" | ||
|
||
|
||
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Specify the location from where the source should be retrieved. | ||
# Supports git, hg, bzr, svn and HTTP. | ||
# | ||
|
||
s.source = { :git => "https://github.com/KBvsMJ/EBTWaterWaveDemo.git", :tag => "#{s.version}" } | ||
|
||
|
||
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# CocoaPods is smart about how it includes source code. For source files | ||
# giving a folder will include any swift, h, m, mm, c & cpp files. | ||
# For header files it will include any header in the folder. | ||
# Not including the public_header_files will make all headers public. | ||
# | ||
|
||
s.source_files = "EBTWaterWaveView", "EBTWaterWaveView/**/*.{h,m}" | ||
# s.exclude_files = "Classes/Exclude" | ||
|
||
s.public_header_files = "EBTWaterWaveView/**/*.h" | ||
|
||
|
||
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# A list of resources included with the Pod. These are copied into the | ||
# target bundle with a build phase script. Anything else will be cleaned. | ||
# You can preserve files from being cleaned, please don't preserve | ||
# non-essential files like tests, examples and documentation. | ||
# | ||
|
||
# s.resource = "icon.png" | ||
# s.resources = "Resources/*.png" | ||
|
||
# s.preserve_paths = "FilesToSave", "MoreFilesToSave" | ||
|
||
|
||
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# Link your library with frameworks, or libraries. Libraries do not include | ||
# the lib prefix of their name. | ||
# | ||
|
||
# s.framework = "SomeFramework" | ||
s.frameworks = 'UIKit', 'QuartzCore', 'Foundation' | ||
|
||
# s.library = "iconv" | ||
# s.libraries = "iconv", "xml2" | ||
|
||
|
||
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # | ||
# | ||
# If your library depends on compiler flags you can set them in the xcconfig hash | ||
# where they will only apply to your library. If you depend on other Podspecs | ||
# you can include multiple dependencies to ensure it works. | ||
|
||
s.requires_arc = true | ||
|
||
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } | ||
# s.dependency "JSONKit", "~> 1.4" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// EBTWaterImageWaveView.h | ||
// EBTWaterWaveDemo | ||
// | ||
// Created by ebaotong on 16/7/22. | ||
// Copyright © 2016年 com.csst. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class EBTWaterImageWaveView; | ||
|
||
typedef void(^EBTWaterImageWaveViewCompleteHandler)(EBTWaterImageWaveView *waveImageView); | ||
|
||
@interface EBTWaterImageWaveView : UIView | ||
{ | ||
EBTWaterImageWaveViewCompleteHandler waterWaveImageViewCompleteHandler; | ||
} | ||
|
||
/** | ||
* 使用两张图片来实现水波动画 | ||
* | ||
* @param waterDepath 水位值 | ||
* @param backGroundImage 背景图 | ||
* @param fillImage 水波填充的图 | ||
* @param isStillAnimate 设置水波动画是否一直执行 | ||
* @param waveImageCompleteHandler 参数回调 | ||
*/ | ||
|
||
|
||
- (void)showWaterImageWaveViewWithDepath:(CGFloat)waterDepath withWaveBackGroundImage:(UIImage *)backGroundImage withWaveFillImage:(UIImage *)fillImage withWaveStillAnimate:(BOOL)isStillAnimate withWaveImageViewCompleteHandler:(EBTWaterImageWaveViewCompleteHandler) waveImageCompleteHandler; | ||
/** | ||
* 停止水波动画 | ||
*/ | ||
- (void)stopWaterWaveViewAnimation; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// | ||
// EBTWaterImageWaveView.m | ||
// EBTWaterWaveDemo | ||
// | ||
// Created by ebaotong on 16/7/22. | ||
// Copyright © 2016年 com.csst. All rights reserved. | ||
// | ||
|
||
#import "EBTWaterImageWaveView.h" | ||
#define kMAXYValue 2.5 | ||
#define kWeakSelf(weakSelf) __weak __typeof(self)weakSelf = self | ||
|
||
@interface EBTWaterImageWaveView () | ||
{ | ||
UIImageView * backGroundImageView; | ||
UIImageView * fillImageView; | ||
BOOL waveImageDirection; | ||
CGFloat waveImageMaxYValue ;//用来控制y坐标的值 | ||
CGFloat waveImageXValue;//改变x坐标的值 | ||
CGFloat waterWaveImageDepath;//设置image的深度 | ||
CGRect waveImageFrame; //frame | ||
UIImage *waveBackImage; | ||
UIImage *waveFillImage; | ||
|
||
|
||
} | ||
@property(nonatomic,strong) NSTimer *timer; | ||
@end | ||
|
||
@implementation EBTWaterImageWaveView | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame { | ||
if (self = [super initWithFrame:frame]) { | ||
|
||
self.backgroundColor = [UIColor clearColor]; | ||
waveImageDirection = NO; | ||
waveImageMaxYValue = kMAXYValue; | ||
waveImageXValue = 0; | ||
backGroundImageView = [[UIImageView alloc]init]; | ||
backGroundImageView.frame = self.bounds; | ||
backGroundImageView.contentMode = UIViewContentModeScaleAspectFit; | ||
[self addSubview:backGroundImageView]; | ||
|
||
fillImageView = [[UIImageView alloc]init]; | ||
fillImageView.frame = self.bounds; | ||
fillImageView.contentMode = UIViewContentModeScaleAspectFit; | ||
[self addSubview:fillImageView]; | ||
|
||
|
||
|
||
} | ||
return self; | ||
} | ||
- (void)awakeFromNib{ | ||
|
||
self.backgroundColor = [UIColor clearColor]; | ||
waveImageDirection = NO; | ||
waveImageMaxYValue = kMAXYValue; | ||
waveImageXValue = 0; | ||
|
||
backGroundImageView = [UIImageView new]; | ||
backGroundImageView.frame = self.bounds; | ||
backGroundImageView.contentMode = UIViewContentModeScaleAspectFit; | ||
backGroundImageView.image = waveBackImage; | ||
[self addSubview:backGroundImageView]; | ||
|
||
fillImageView = [UIImageView new]; | ||
fillImageView.frame = self.bounds; | ||
fillImageView.contentMode = UIViewContentModeScaleAspectFit; | ||
[self addSubview:fillImageView]; | ||
|
||
|
||
|
||
|
||
} | ||
- (NSTimer *)timer{ | ||
|
||
if (!_timer) { | ||
_timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(waterFillWave) userInfo:nil repeats:YES]; | ||
} | ||
return _timer; | ||
|
||
} | ||
- (void)stopTimer{ | ||
|
||
[self.timer invalidate]; | ||
self.timer = nil; | ||
|
||
|
||
} | ||
//停止定时器 | ||
- (void)stopWaterWaveViewAnimation{ | ||
|
||
[self stopTimer]; | ||
|
||
} | ||
|
||
- (void)dealloc{ | ||
[self stopTimer]; | ||
} | ||
|
||
- (void)waterFillWave{ | ||
|
||
waveImageMaxYValue += waveImageDirection?0.01f:-0.01f; | ||
if (waveImageMaxYValue<=kMAXYValue) { | ||
waveImageDirection = YES; | ||
} | ||
else if (waveImageMaxYValue>=kMAXYValue){ | ||
waveImageDirection = NO; | ||
} | ||
waveImageXValue += 0.1f; | ||
|
||
[self createWavePath]; | ||
|
||
} | ||
//绘制水波 | ||
- (void)createWavePath{ | ||
|
||
/**----------xib或者sb需要重新布局frame获取最新的frame-------------*/ | ||
[self layoutIfNeeded]; | ||
fillImageView.frame = self.bounds; | ||
backGroundImageView.frame = self.bounds; | ||
|
||
waveImageFrame = self.bounds; | ||
/**----------xib或者sb需要重新布局frame获取最新的frame-------------*/ | ||
CAShapeLayer *shapelayer = [CAShapeLayer layer]; | ||
UIBezierPath *path = [UIBezierPath bezierPath]; | ||
CGFloat waterWaveY = (1 - (waterWaveImageDepath > 1.f? 1.f :waterWaveImageDepath)) * waveImageFrame.size.height; | ||
CGFloat y = waterWaveY; | ||
[path moveToPoint:CGPointMake(0, y)]; | ||
path.lineWidth = 1.f; | ||
for (CGFloat x = 0; x<= waveImageFrame.size.width; x++) { | ||
y = waveImageMaxYValue*sin(x/180*M_PI+4*waveImageXValue/M_PI)*5 + waterWaveY; | ||
[path addLineToPoint:CGPointMake(x, y)]; | ||
} | ||
[path addLineToPoint:CGPointMake(waveImageFrame.size.width, y)]; | ||
[path addLineToPoint:CGPointMake(waveImageFrame.size.width, waveImageFrame.size.height)]; | ||
[path addLineToPoint:CGPointMake(0, waveImageFrame.size.height)]; | ||
shapelayer.path = path.CGPath; | ||
backGroundImageView.image = waveBackImage; | ||
fillImageView.image = waveFillImage; | ||
fillImageView.layer.mask = shapelayer; | ||
[path closePath]; | ||
if (waterWaveImageViewCompleteHandler) { | ||
waterWaveImageViewCompleteHandler(self); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
- (void)showWaterImageWaveViewWithDepath:(CGFloat)waterDepath withWaveBackGroundImage:(UIImage *)backGroundImage withWaveFillImage:(UIImage *)fillImage withWaveStillAnimate:(BOOL)isStillAnimate withWaveImageViewCompleteHandler:(EBTWaterImageWaveViewCompleteHandler) waveImageCompleteHandler{ | ||
|
||
waterWaveImageDepath = waterDepath; | ||
waveBackImage = backGroundImage; | ||
waveFillImage = fillImage; | ||
waterWaveImageViewCompleteHandler = waveImageCompleteHandler; | ||
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; | ||
kWeakSelf(weakSelf); | ||
if (!isStillAnimate) { | ||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
[weakSelf stopWaterWaveViewAnimation]; | ||
}); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// EBTWaterWaveView.h | ||
// EBTWaterWaveDemo | ||
// | ||
// Created by ebaotong on 16/7/21. | ||
// Copyright © 2016年 com.csst. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class EBTWaterWaveView; | ||
typedef void(^EBTWaterWaveViewCompleteHandler)(EBTWaterWaveView *waterWaveView); | ||
/** | ||
* 用uiview来实现水波动画 | ||
*/ | ||
@interface EBTWaterWaveView : UIView | ||
{ | ||
EBTWaterWaveViewCompleteHandler waterWaveCompleteHandler; | ||
} | ||
/** | ||
* 显示水波动画 | ||
* | ||
* @param waterDepath 水波动画水平值 | ||
* @param waveColor 水波的颜色 | ||
* @param isStillAnimate 水波是否一直显示动画 | ||
* @param waveCompleteHandler 参数回调 | ||
*/ | ||
-(void)showWaterWaveViewWithDepath:(CGFloat)waterDepath withWaveFillColor:(UIColor *)waveColor withWaveStillAnimate:(BOOL)isStillAnimate withWaterWaveCompleteHandler:(EBTWaterWaveViewCompleteHandler)waveCompleteHandler; | ||
|
||
/** | ||
* 移除水波动画 | ||
*/ | ||
- (void)stopWaterWaveViewAnimation; | ||
|
||
|
||
@end |
Oops, something went wrong.