-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabBarInSplitViewMasterViewController.m
More file actions
88 lines (71 loc) · 3.97 KB
/
TabBarInSplitViewMasterViewController.m
File metadata and controls
88 lines (71 loc) · 3.97 KB
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
//
// TabBarInSplitViewMasterViewController.m
// xolawareUI - freeforall
//
// Created by kb on 2012.11.02.
#import "xolawareOpenSourceCopyright.h"
#import "TabBarInSplitViewMasterViewController.h"
#import "UISplitViewController+MasterDetailUtilities.h"
@interface TabBarInSplitViewMasterViewController () <UISplitViewControllerDelegate>
@end
@implementation TabBarInSplitViewMasterViewController
#pragma mark - UIViewController @property implementation overrides
- (NSString*)title {
if (((UINavigationController*)self.selectedViewController).topViewController.title)
return ((UINavigationController*)self.selectedViewController).topViewController.title;
if (self.selectedViewController.title)
return self.selectedViewController.title;
return [[[self.viewControllers objectAtIndex:0] tabBarItem] title];
}
#pragma mark - UISplitViewControllerDelegate protocol implementation
#pragma mark @optional
- (BOOL) splitViewController:(UISplitViewController*)svc
shouldHideViewController:(UIViewController*)vc
inOrientation:(UIInterfaceOrientation)orientation
{
if (UIInterfaceOrientationIsLandscape(orientation))
return NO;
if (![self.selectedViewController respondsToSelector:@selector(topViewController)])
return YES;
if (![[(id)self.selectedViewController topViewController] respondsToSelector:@selector(tableView)])
return YES;
return ![(id)[(id)self.selectedViewController topViewController] tableView].isEditing;
}
- (void)splitViewController:(UISplitViewController*)splitController
willHideViewController:(UIViewController*)viewController
withBarButtonItem:(UIBarButtonItem*)barButtonItem
forPopoverController:(UIPopoverController *)popoverController
{
UINavigationController* detailVC = (id)splitController.detailUIViewController;
[detailVC.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
detailVC.navigationItem.leftBarButtonItem.title = self.splitViewController.masterTitle;
}
// the following is a workaround for bug at startup whereby the back button flashes up in
// landscape mode (at least on iOS simulator for iPad); the root cause is that
// 1) splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
// 2) splitViewController:willShowViewController:invalidatingBarButtonItem:
// both get called when only (2) should be called. an attempt was made to use the normal check
// of (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])), but that always
// returns YES for (1) and NO for (2). another workaround was to try to not set the bar-button
// title until later, but no sequence would guarantee a button in portrait combined with no
// flashing in landscape.
//
// in the end, while the real problem is that the button never should have been shown so that
// hiding it would e a no-op, the cosmetic part of the problem is that there are two animations,
// the showing of the button and then the hiding of it. so, the cosmetic solution is to simply
// make certain not to show both animations. fortunately, iOS animations works in such a way
// that performing the same operation on a UI element without animation after an operation that
// performed animation suppresses the first animation. thus, by turning off animation on the
// second hide but force hiding the button, it suppresses the animation from (1) above. and by
// using the counter and just incrementing it, we effectively get 4-billion rotations before
// the button is not animated when switching to landscape. ... good enough!!!
static NSUInteger KLUDGE_ANIMATION_WORKAROUND = 0;
- (void)splitViewController:(UISplitViewController*)splitController
willShowViewController:(UIViewController*)viewController
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
UINavigationController* detailVC = (id)splitController.detailUIViewController;
[detailVC.navigationItem setLeftBarButtonItem:nil animated:KLUDGE_ANIMATION_WORKAROUND++];
}
@end