-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathLRPopoverManager.m
102 lines (81 loc) · 4.15 KB
/
LRPopoverManager.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
//
// LRPopoverManager.m
// Spark
//
// Created by Luke Redpath on 24/05/2010.
// Copyright 2010 LJR Software Limited. All rights reserved.
//
#import "LRPopoverManager.h"
NSString *const LRUIPopoverControllerDidDismissNotification = @"LRUIPopoverControllerDidDismissNotification";
@implementation LRPopoverManager
@synthesize currentPopoverController;
@synthesize permitCurrentPopoverControllerToDismiss;
static LRPopoverManager *sharedManager = nil;
+ (void)initialize {
if (self == [LRPopoverManager class]) {
sharedManager = [[self alloc] init];
sharedManager.permitCurrentPopoverControllerToDismiss = YES;
}
}
+ (id)sharedManager {
return sharedManager;
}
- (void)setCurrentPopoverController:(UIPopoverController *)pc
{
[self dismissCurrentPopoverController:YES];
if (pc != currentPopoverController) {
[currentPopoverController release];
currentPopoverController = [pc retain];
currentPopoverController.delegate = self;
}
self.permitCurrentPopoverControllerToDismiss = YES;
}
- (void)presentPopoverController:(UIPopoverController *)pc fromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
{
self.currentPopoverController = pc;
[self.currentPopoverController presentPopoverFromRect:rect inView:view permittedArrowDirections:arrowDirections animated:animated];
}
- (void)presentPopoverController:(UIPopoverController *)pc fromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
{
self.currentPopoverController = pc;
[self.currentPopoverController presentPopoverFromBarButtonItem:item permittedArrowDirections:arrowDirections animated:animated];
}
- (void)dismissCurrentPopoverController:(BOOL)animated;
{
[self.currentPopoverController dismissPopoverAnimated:animated];
}
- (void)presentControllerInPopoverController:(UIViewController *)vc fromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
{
UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];
[self presentPopoverController:pc fromRect:rect inView:view permittedArrowDirections:arrowDirections animated:animated];
[pc release];
}
- (void)presentControllerInPopoverController:(UIViewController *)vc fromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
{
UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];
[self presentPopoverController:pc fromBarButtonItem:item permittedArrowDirections:arrowDirections animated:animated];
[pc release];
}
- (void)presentControllerWithNavigationInPopoverController:(UIViewController *)vc fromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentControllerInPopoverController:navigationController fromRect:rect inView:view permittedArrowDirections:arrowDirections animated:animated];
[navigationController release];
}
- (void)presentControllerWithNavigationInPopoverController:(UIViewController *)vc fromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentControllerInPopoverController:navigationController fromBarButtonItem:item permittedArrowDirections:arrowDirections animated:animated];
[navigationController release];
}
#pragma mark -
#pragma mark UIPopoverControllerDelegate methods
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
[[NSNotificationCenter defaultCenter] postNotificationName:LRUIPopoverControllerDidDismissNotification object:popoverController];
}
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return self.permitCurrentPopoverControllerToDismiss;
}
@end