-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIViewController+iOsUtils.m
62 lines (55 loc) · 1.8 KB
/
UIViewController+iOsUtils.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
//
// UIViewController+iOsUtils.m
// Instabank
//
// Created by Aleksey Kozhevnikov on 02.11.12.
// Copyright (c) 2012 iDa Mobile. All rights reserved.
//
#import "UIViewController+iOsUtils.h"
@implementation UIViewController(iOsUtils)
-(void)dismissPresentedViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
if( !self.presentedViewController ) {
if( completion ) {
completion();
}
} else {
[self dismissViewControllerAnimated:flag completion:completion];
}
}
-(void)dismissSelfAnimated:(BOOL)flag
{
NSUInteger indexOfSelf = NSNotFound;
UIViewController* previousVC = nil;
if( self.navigationController ) {
NSArray* viewControllers = self.navigationController.viewControllers;
indexOfSelf = [viewControllers indexOfObject:self];
if( indexOfSelf != NSNotFound && indexOfSelf > 0 ) {
previousVC = viewControllers[indexOfSelf - 1];
}
}
if( self.navigationController && indexOfSelf != NSNotFound ) {
if( !previousVC ) {
[self.navigationController dismissSelfAnimated:flag];
} else {
[self.navigationController popToViewController:previousVC animated:YES];
}
} else if( self.presentingViewController && self.presentingViewController.presentedViewController == self ) {
[self.presentingViewController dismissViewControllerAnimated:flag completion:^{}];
}
}
-(void)dismissSelfAnimated
{
[self dismissSelfAnimated:YES];
}
-(UIViewController*)presentationHierarchyTopSuccessor
{
if( self.navigationController && self.navigationController.viewControllers.count > 0 ) {
return [[self.navigationController topViewController] presentationHierarchyTopSuccessor];
} else if( self.presentedViewController ) {
return [self.presentedViewController presentationHierarchyTopSuccessor];
} else {
return self;
}
}
@end