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
/
RFContainedSegue.m
47 lines (37 loc) · 1.54 KB
/
RFContainedSegue.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
#import "RFContainedSegue.h"
@interface RFContainedSegue ()
@end
@implementation RFContainedSegue
- (BOOL)shouldPerform {
if (![super shouldPerform]) {
return NO;
}
if ([self.sourceViewController respondsToSelector:@selector(RFContainedSegueShouldPerformWhileControllerHavingSameClass:)]) {
BOOL canBeSameClass = [self.sourceViewController RFContainedSegueShouldPerformWhileControllerHavingSameClass:self];
BOOL isSameClass = ([self.destinationViewController class] == [[self.sourceViewController containedViewController] class]);
if (!canBeSameClass && isSameClass) {
return NO;
}
}
return YES;
}
- (void)RFPerform {
[self noticeDelegateWillPerform];
UIViewController<RFContainedSegueSourceDelegate> *vcContainer = self.sourceViewController;
UIViewController *vcOld = vcContainer.containedViewController;
UIViewController *vcNew = self.destinationViewController;
if (vcOld) {
[vcOld willMoveToParentViewController:nil];
[vcOld.view removeFromSuperview];
[vcOld removeFromParentViewController];
}
if (vcNew) {
[vcContainer addChildViewController:vcNew];
[vcContainer.containedViewHolder addSubview:vcNew.view resizeOption:RFViewResizeOptionFill];
vcNew.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[vcNew didMoveToParentViewController:vcContainer];
}
vcContainer.containedViewController = vcNew;
[self noticeDelegateDidPerformed];
}
@end