forked from coolstar/displaycandy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DCCoverTransitionView.m
40 lines (32 loc) · 1.15 KB
/
DCCoverTransitionView.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
#import <QuartzCore/QuartzCore.h>
#import "DCTypes.h"
#import "DCCoverTransitionView.h"
@implementation DCCoverTransitionView
- (void)animateWithDuration:(CFTimeInterval)duration {
CGPoint startPoint;
CGSize viewSize = [self frame].size;
switch ([self direction]) {
case DCTransitionDirectionLeft:
startPoint = CGPointMake(viewSize.width, 0);
break;
case DCTransitionDirectionRight:
startPoint = CGPointMake(-viewSize.width, 0);
break;
case DCTransitionDirectionUp:
startPoint = CGPointMake(0, viewSize.height);
break;
case DCTransitionDirectionDown:
startPoint = CGPointMake(0, -viewSize.height);
break;
}
[[self toView] setHidden:NO];
CABasicAnimation *cover = [CABasicAnimation animationWithKeyPath:@"transform.translation"];
[cover setDelegate:[self delegate]];
[cover setValue:@([self mode]) forKey:@"mode"];
[cover setFromValue:[NSValue valueWithCGPoint:startPoint]];
[cover setToValue:[NSValue valueWithCGPoint:CGPointZero]];
[cover setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[cover setDuration:duration];
[[[self toView] layer] addAnimation:cover forKey:nil];
}
@end