This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
/
UIViewControllerAdditions.m
105 lines (80 loc) · 3.21 KB
/
UIViewControllerAdditions.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
102
103
104
105
#import "Three20/TTGlobal.h"
#import "Three20/TTURLRequestQueue.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation UIViewController (TTCategory)
- (void)showNavigationBar:(BOOL)show animated:(BOOL)animated {
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:TT_TRANSITION_DURATION];
}
self.navigationController.navigationBar.alpha = show ? 1 : 0;
if (animated) {
[UIView commitAnimations];
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIViewController*)previousViewController {
NSArray* viewControllers = self.navigationController.viewControllers;
if (viewControllers.count > 1) {
NSUInteger index = [viewControllers indexOfObject:self];
if (index != NSNotFound) {
return [viewControllers objectAtIndex:index-1];
}
}
return nil;
}
- (UIViewController*)nextViewController {
NSArray* viewControllers = self.navigationController.viewControllers;
if (viewControllers.count > 1) {
NSUInteger index = [viewControllers indexOfObject:self];
if (index != NSNotFound && index+1 < viewControllers.count) {
return [viewControllers objectAtIndex:index+1];
}
}
return nil;
}
- (void)alert:(NSString*)message title:(NSString*)title delegate:(id)delegate {
if (message) {
UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:title message:message
delegate:delegate cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[alert show];
}
}
- (void)alert:(NSString*)message {
[self alert:message title:@"Alert" delegate:nil];
}
- (void)alertError:(NSString*)message {
[self alert:message title:@"Error" delegate:nil];
}
- (void)showBars:(BOOL)show animated:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarHidden:!show animated:animated];
[self showNavigationBar:show animated:animated];
}
@end
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation UINavigationController (TTCategory)
- (void)pushAnimationDidStop {
[TTURLRequestQueue mainQueue].suspended = NO;
}
- (void)pushViewController:(UIViewController*)controller
animatedWithTransition:(UIViewAnimationTransition)transition {
[TTURLRequestQueue mainQueue].suspended = YES;
[self pushViewController:controller animated:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
- (void)popViewControllerAnimatedWithTransition:(UIViewAnimationTransition)transition {
[TTURLRequestQueue mainQueue].suspended = YES;
[self popViewControllerAnimated:NO];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:TT_FLIP_TRANSITION_DURATION];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pushAnimationDidStop)];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
@end