-
Notifications
You must be signed in to change notification settings - Fork 0
/
PAPrayListTableViewCell.m
150 lines (125 loc) · 5.11 KB
/
PAPrayListTableViewCell.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// PAPrayListTableViewCell.m
// prayApp
//
// Created by Jeff Wang on 8/14/13.
// Copyright (c) 2013 Jeff Wang. All rights reserved.
//
#import "PAPrayListTableViewCell.h"
#define kCheckerViewInitX -320
#define kCheckerViewCheckXoffset -260;
@interface PAPrayListTableViewCell (){
UIPanGestureRecognizer* panGR;
UILabel* markLabel;
UILabel* accessoryView;
}
@end
@implementation PAPrayListTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
// TODO: Will Need an image
accessoryView = [[UILabel alloc] initWithFrame:CGRectMake(320 - 33, 0, 33, self.bounds.size.height)];
accessoryView.text = @">";
// self.accessoryView = accessoryView;
[self.contentView addSubview:accessoryView];
// Set up the gesture recognizer
panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightToCheck:)];
[self addGestureRecognizer:panGR];
// This is view thats dragable.
checkConfirmView = [[UIView alloc] initWithFrame:CGRectMake(kCheckerViewInitX, 0, 320, self.frame.size.height)];
checkConfirmView.backgroundColor = [UIColor lightGrayColor];
markLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 310, 60)];
markLabel.text = @"Pray";
markLabel.textAlignment = NSTextAlignmentRight;
[checkConfirmView addSubview:markLabel];
self.contentView.backgroundColor = [UIColor whiteColor];
[self insertSubview:checkConfirmView atIndex:0];
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
CGRect frame = accessoryView.frame;
frame.size.height = self.frame.size.height;
accessoryView.frame = frame;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
// This function will update the text.
- (void) updateWithPrayer:(PAPrayer *)prayerItem{
self.textLabel.text = prayerItem.prayerTitle;
self.detailTextLabel.text = prayerItem.prayerContext;
}
- (void)swipeRightToCheck:(UIPanGestureRecognizer*) gr{
// At the beginning.
if ([gr state] == UIGestureRecognizerStateBegan){
CGRect frame = checkConfirmView.frame;
frame.size.height = self.frame.size.height;
checkConfirmView.frame = frame;
}
else if ([gr state] == UIGestureRecognizerStateEnded){
// The user release to mark as prayed
if (checkConfirmView.backgroundColor == [UIColor greenColor]){
[UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
CGRect frame = self.contentView.frame;
frame.origin.x = 60;
self.contentView.frame = frame;
checkConfirmView.alpha = 1;
frame = checkConfirmView.frame;
frame.origin.x = kCheckerViewCheckXoffset;
checkConfirmView.frame = frame;
markLabel.text = @">";
} completion:^(BOOL finished) {
[self removeGestureRecognizer:panGR];
}];
}
else{
[UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
CGRect frame = self.contentView.frame;
frame.origin.x = 0;
self.contentView.frame = frame;
checkConfirmView.alpha = 0;
frame = checkConfirmView.frame;
frame.origin.x = kCheckerViewInitX;
checkConfirmView.frame = frame;
} completion:^(BOOL finished) {
}];
}
}
else{
CGFloat xValue = [gr translationInView:self.contentView].x;
CGFloat ratio = 0;
if (xValue > 60)
ratio = 1;
else
ratio = xValue/60;
if (ratio == 1)
checkConfirmView.backgroundColor = [UIColor greenColor];
else if (xValue > 120)
checkConfirmView.backgroundColor = [UIColor brownColor];
else
checkConfirmView.backgroundColor = [UIColor lightGrayColor];
[UIView animateWithDuration:0.1 animations:^{
checkConfirmView.alpha = ratio;
// -260
if (YES){
// if (ratio == 1){
CGRect frame = checkConfirmView.frame;
frame.origin.x = xValue -320;
checkConfirmView.frame = frame;
}
CGRect frame = self.contentView.frame;
frame.origin.x = xValue;
self.contentView.frame = frame;
frame = self.accessoryView.frame;
}];
}
}
@end