This repository has been archived by the owner on Aug 7, 2020. It is now read-only.
forked from RFUI/RFSegue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RFSegue.m
81 lines (66 loc) · 2.79 KB
/
RFSegue.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
#import "RFSegue.h"
#import "RFSegueExternLink.h"
//! REF: http://stackoverflow.com/a/24423494
NSTimeInterval RFSegueNavigationTransitionDuration = 0.51f;
@implementation RFSegue
+ (void)load {
RFSegueNavigationTransitionDuration = RF_iOS7Before? 0.36f : 0.511f;
}
- (instancetype)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController<RFSegueExternLink> *)destination {
// Load from external storyboard
if ([destination respondsToSelector:@selector(externalStoryboardName)]
&& [destination respondsToSelector:@selector(externalScenceIdentifier)]) {
// Only load from external when storyboard name specified
if (destination.externalStoryboardName) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:destination.externalStoryboardName bundle:nil];
UIViewController *vc = destination.externalScenceIdentifier? [sb instantiateViewControllerWithIdentifier:destination.externalScenceIdentifier] : [sb instantiateInitialViewController];
if (vc) {
destination = (id)vc;
}
}
}
self = [super initWithIdentifier:identifier source:source destination:destination];
return self;
}
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p; sourceViewController: %@; destinationViewController: %@; identifier:%@; userInfo:%@>",
NSStringFromClass([self class]),
self,
self.sourceViewController,
self.destinationViewController,
self.identifier,
self.userInfo];
}
- (BOOL)shouldPerform {
BOOL shouldPerform = YES;
if ([self.sourceViewController respondsToSelector:@selector(RFSegueShouldPerform:)]) {
shouldPerform = [self.sourceViewController RFSegueShouldPerform:self];
}
return shouldPerform;
}
- (void)perform {
if (![self shouldPerform]) return;
[self RFPerform];
}
- (void)RFPerform {
[self noticeDelegateWillPerform];
RFAssert(false, @"You should subclass RFSegue and override RFPerform.");
[self noticeDelegateDidPerformed];
}
- (void)noticeDelegateWillPerform {
if ([self.sourceViewController respondsToSelector:@selector(RFSegueWillPerform:)]) {
[self.sourceViewController RFSegueWillPerform:self];
}
if ([self.destinationViewController respondsToSelector:@selector(RFSegueWillAppear:)]) {
[self.destinationViewController RFSegueWillAppear:self];
}
}
- (void)noticeDelegateDidPerformed {
if ([self.sourceViewController respondsToSelector:@selector(RFSegueDidPerform:)]) {
[self.sourceViewController RFSegueDidPerform:self];
}
if ([self.destinationViewController respondsToSelector:@selector(RFSegueDidAppear:)]) {
[self.destinationViewController RFSegueDidAppear:self];
}
}
@end