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