-
Notifications
You must be signed in to change notification settings - Fork 0
/
DCBuiltInTransitionView.m
87 lines (72 loc) · 2.54 KB
/
DCBuiltInTransitionView.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
#import <QuartzCore/QuartzCore.h>
#import "SpringBoard-Minimal.h"
#import "DCSettings.h"
#import "DCTypes.h"
#import "DCBuiltInTransitionView.h"
#include "DCFunctions.h"
@interface CAFilter : NSObject
+ (id)filterWithName:(NSString *)name;
@end
@interface DCBuiltInTransitionView ()
- (NSString *)stringForDirection:(DCTransitionDirection)direction;
- (CGPoint)homeButtonPointForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end
@implementation DCBuiltInTransitionView
- (void)animateWithDuration:(CFTimeInterval)duration
{
CATransition *animation = [CATransition animation];
[animation setDelegate:[self delegate]];
[animation setValue:@([self mode]) forKey:@"mode"];
[animation setType:[self type]];
[animation setDuration:duration];
if ([[self type] isEqualToString:@"cube"] || [[self type] isEqualToString:@"oglFlip"])
[animation setSubtype:[self stringForDirection:[self direction]]];
if ([[self type] isEqualToString:@"suckEffect"]) {
CGSize viewSize = [self frame].size;
CAFilter *suckFilter = [CAFilter filterWithName:@"suckEffect"];
CGPoint suckPoint = ([[DCSettings sharedSettings] suckPointForMode:[self mode]] == 0)
? [self homeButtonPointForInterfaceOrientation:[[UIApplication sharedApplication] activeInterfaceOrientation]]
: CGPointMake(viewSize.width / 2, viewSize.height / 2);
[suckFilter setValue:[NSValue valueWithCGPoint:suckPoint] forKey:@"inputPosition"];
[animation setFilter:suckFilter];
}
[[self toView] setHidden:NO];
[[self layer] addAnimation:animation forKey:nil];
}
- (void)dealloc
{
[_type release];
[super dealloc];
}
- (NSString *)stringForDirection:(DCTransitionDirection)direction
{
switch (direction) {
case DCTransitionDirectionLeft:
return @"fromRight";
case DCTransitionDirectionRight:
return @"fromLeft";
case DCTransitionDirectionUp:
return @"fromTop";
case DCTransitionDirectionDown:
return @"fromBottom";
default:
return @"fromLeft";
}
}
- (CGPoint)homeButtonPointForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
CGSize viewSize = [self frame].size;
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
return CGPointMake(viewSize.width / 2, viewSize.height);
case UIInterfaceOrientationPortraitUpsideDown:
return CGPointMake(viewSize.width / 2, 0);
case UIInterfaceOrientationLandscapeLeft:
return CGPointMake(0, viewSize.height / 2);
case UIInterfaceOrientationLandscapeRight:
return CGPointMake(viewSize.width, viewSize.height / 2);
default:
return CGPointZero;
}
}
@end