11
11
12
12
#define kFlipVerticalTime 0.5
13
13
#define kFlipHorizontalTime 0.6
14
+ #define kDelayTime 0.0
15
+ #define kAnimationEasingType UIViewAnimationOptionCurveEaseInOut
14
16
15
17
@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
16
18
@property IBOutlet UITableView *tableView;
17
19
@property NSArray *tableViewDataSource;
18
20
@end
19
21
20
- typedef enum : NSUInteger {
21
- kClockWiseDirection = -1 ,
22
- kAntiClockWiseDirection = 1 ,
23
- } kRotationDirection ;
24
22
25
23
@implementation ViewController
26
24
@@ -80,12 +78,12 @@ - (void)buttonPressed:(UIButton *)sender {
80
78
NSTimeInterval timeInterval = kFlipHorizontalTime ;
81
79
NSString *msg = @" Hello is now changed" ;
82
80
int tag = 3 ;
83
- cell.layer .transform = [self performHorizontalFlipInDirection: kClockWiseDirection ];
81
+ cell.layer .transform = [self performHorizontalFlipInClockwiseDirection: YES ];
84
82
if (sender.tag ) {
85
83
tag = 4 ;
86
84
timeInterval = kFlipVerticalTime ;
87
85
msg = @" World is now changed" ;
88
- cell.layer .transform = [self performVerticalFlipInDirection: kClockWiseDirection ];
86
+ cell.layer .transform = [self performVerticalFlipInClockwiseDirection: YES ];
89
87
}
90
88
91
89
@@ -100,8 +98,8 @@ - (void)buttonPressed:(UIButton *)sender {
100
98
NSString *imageName = [NSString stringWithFormat: @" %d .jpg" , tag];
101
99
102
100
[UIView animateWithDuration: timeInterval
103
- delay: 0.0
104
- options: UIViewAnimationOptionCurveEaseInOut
101
+ delay: kDelayTime
102
+ options: kAnimationEasingType
105
103
animations: ^{
106
104
cell.layer .transform = CATransform3DIdentity;
107
105
cell.textLabel .textColor = [UIColor whiteColor ];
@@ -122,11 +120,12 @@ - (void)revert:(UIButton *)sender {
122
120
123
121
NSString *msg = @" Hello" ;
124
122
NSTimeInterval timeInterval = kFlipHorizontalTime ;
125
- cell.layer .transform = [self performHorizontalFlipInDirection: kClockWiseDirection ];
123
+ cell.layer .transform = [self performHorizontalFlipInClockwiseDirection: YES ];
126
124
if (sender.tag ) {
127
125
timeInterval = kFlipVerticalTime ;
128
126
msg = @" World" ;
129
- cell.layer .transform = [self performVerticalFlipInDirection: kClockWiseDirection ];
127
+ cell.layer .transform = [self performVerticalFlipInClockwiseDirection: YES ];
128
+
130
129
}
131
130
132
131
NSString *imageName = [NSString stringWithFormat: @" %d .jpg" , sender.tag];
@@ -141,8 +140,8 @@ - (void)revert:(UIButton *)sender {
141
140
[button addTarget: self action: @selector (buttonPressed: ) forControlEvents: UIControlEventTouchUpInside];
142
141
143
142
[UIView animateWithDuration: timeInterval
144
- delay: 0.0
145
- options: UIViewAnimationOptionCurveEaseInOut
143
+ delay: kDelayTime
144
+ options: kAnimationEasingType
146
145
animations: ^{
147
146
cell.layer .transform = CATransform3DIdentity;
148
147
cell.textLabel .textColor = [UIColor whiteColor ];
@@ -158,36 +157,34 @@ - (void)revert:(UIButton *)sender {
158
157
}];
159
158
}
160
159
161
- - (CATransform3D)performVerticalFlipInDirection : ( kRotationDirection )clockwise {
162
- return [self getTransformForIndex: 1 inDirection: kClockWiseDirection ];
160
+ - (CATransform3D)performVerticalFlipInClockwiseDirection : ( BOOL )clockwise {
161
+ return [self getTransformForIndex: 1 inClockwiseDirection: clockwise ];
163
162
}
164
163
165
- - (CATransform3D)performHorizontalFlipInDirection : ( kRotationDirection )clockwise {
166
- return [self getTransformForIndex: 0 inDirection : clockwise];
164
+ - (CATransform3D)performHorizontalFlipInClockwiseDirection : ( BOOL )clockwise {
165
+ return [self getTransformForIndex: 0 inClockwiseDirection : clockwise];
167
166
}
168
167
169
- - (CATransform3D)getTransformForIndex : (int )index inDirection : (kRotationDirection )clockwise {
170
- int direction = -1 ;
168
+ - (CATransform3D)getTransformForIndex : (int )index inClockwiseDirection : (BOOL )clockwise {
169
+
170
+ int direction = clockwise ? -1 : 1 ;
171
171
172
- float xCord = 0.0 ;
173
- float yCord = 1.0 ;
172
+ float xCord = index ? 1.0 : 0.0 ;
173
+ float yCord = index ? 0.0 : 1.0 ;
174
174
float zCord = 0.0 ;
175
175
176
+ // float angle = (180 * direction) * (M_PI / 180);
177
+ float angle = direction * M_PI;
176
178
177
- if (clockwise) direction = 1 ;
179
+ CGPoint offset = CGPointMake ( 0 , 0 ) ;
178
180
179
- float rotateAngleBy = (180 * direction) * (M_PI / 180 );
180
- CGPoint offsetPositioning = CGPointMake (0 , 0 );
181
+ CATransform3D transform = CATransform3DIdentity;
182
+
183
+ transform = CATransform3DRotate (transform, angle, xCord, yCord, zCord);
184
+
185
+ transform = CATransform3DTranslate (transform, offset.x , offset.y , 0.0 );
181
186
182
- CATransform3D transform = CATransform3DIdentity;
183
-
184
- if (index ) {
185
- xCord = 1.0 ; yCord = 0.0 ;
186
- }
187
-
188
- transform = CATransform3DRotate (transform, rotateAngleBy, xCord, yCord, zCord);
189
-
190
- transform = CATransform3DTranslate (transform, offsetPositioning.x , offsetPositioning.y , 0.0 );
187
+
191
188
return transform;
192
189
}
193
190
0 commit comments