/
ViewController.m
55 lines (43 loc) · 1.6 KB
/
ViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// ViewController.m
// WaterWaveDemo
//
// Created by Antonio081014 on 9/4/15.
// Copyright (c) 2015 antonio081014.com. All rights reserved.
//
#import "ViewController.h"
#import "SPWaterProgressIndicatorView.h"
@interface ViewController ()
@property (nonatomic, strong) SPWaterProgressIndicatorView *waterView;
@property (nonatomic) BOOL isAnimating;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.waterView = [[SPWaterProgressIndicatorView alloc] initWithFrame:self.view.bounds];
self.waterView.center = self.view.center;
[self.view addSubview:self.waterView];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(updateAnimation)];
[self.waterView addGestureRecognizer:gesture];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(updatePercent:)];
[self.waterView addGestureRecognizer:panGesture];
self.isAnimating = YES;
}
- (void)updatePercent:(UIPanGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateChanged || gesture.state == UIGestureRecognizerStateEnded) {
CGPoint location = [gesture locationInView:self.waterView];
NSUInteger percent = 100 - 100 * location.y / CGRectGetHeight(self.waterView.bounds);
[self.waterView updateWithPercentCompletion:percent];
}
}
- (void)updateAnimation
{
self.isAnimating = !self.isAnimating;
if (self.isAnimating) {
[self.waterView startAnimation];
} else {
[self.waterView stopAnimation];
}
}
@end