forked from rickardp/iqwidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIQViewTransition.m
101 lines (90 loc) · 2.63 KB
/
IQViewTransition.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
//
// IQViewTransition.m
// IQWidgets
//
// Created by Rickard Petzäll on 2011-05-11.
// Copyright 2011 EvolvIQ. All rights reserved.
//
#import "IQViewTransition.h"
@interface IQViewTransition ()
- (void) stop;
@end
@implementation IQViewTransition
static IQViewTransition* activeTransition;
+ (void) stopTransitions
{
if(activeTransition) {
IQViewTransition* trans = activeTransition;
activeTransition = nil;
[trans stop];
[trans release];
}
}
- (void) doTransitionStart
{
transform.hidden = YES;
[from.superview addSubview:transform];
[transform setTransitionViewsFrom:from to:to];
[transform presentFrame];
transform.hidden = NO;
}
+ (void) transitionFrom:(UIView*)fromView to:(UIView*)toView duration:(NSTimeInterval)duration withTransformation:(IQViewTesselationTransformation)transformation completion:(IQTransitionCompletionBlock)complete {
if(fromView.superview != toView.superview) {
[NSException raise:@"MustShareSuperview" format:@"Transition between views with different superviews is currently unsupported"];
}
IQViewTransition* trans = [[IQViewTransition alloc] init];
if(trans != nil) {
trans->from = [fromView retain];
trans->to = [toView retain];
trans->transform = [[IQViewTessellation alloc] initWithFrame:fromView.frame withTilesHorizontal:8 vertical:24];
if(complete) trans->complete = Block_copy(complete);
trans->transform.transformation = ^(CGPoint pt, CGFloat t) {
if(t >= duration) {
[trans stop];
}
if(transformation == nil) {
return IQMakePoint3(pt.x, pt.y, 0);
} else {
return transformation(pt, t);
}
};
//toView.hidden = NO;
[trans performSelectorOnMainThread:@selector(doTransitionStart) withObject:trans waitUntilDone:NO];
}
}
- (void) dealloc
{
if(complete) Block_release(complete);
complete = nil;
IQViewTessellation* tf = transform;
transform = nil;
tf.transformation = nil;
[tf release];
[from release];
from = nil;
[to release];
to = nil;
[super dealloc];
};
- (void) stop
{
if(stopped) return;
stopped = YES;
if(self == activeTransition) {
activeTransition = nil;
}
if(complete) {
complete(from, to);
Block_release(complete);
complete = nil;
}
if(transform) {
[transform stopAnimation];
transform.transformation = nil;
[transform removeFromSuperview];
[transform release];
transform = nil;
}
[self release];
}
@end