Guest User

Untitled

a guest
May 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. //
  2. // LRPopoverManager.m
  3. // Spark
  4. //
  5. // Created by Luke Redpath on 24/05/2010.
  6. // Copyright 2010 LJR Software Limited. All rights reserved.
  7. //
  8.  
  9. #import "LRPopoverManager.h"
  10.  
  11.  
  12. NSString *const LRUIPopoverControllerDidDismissNotification = @"LRUIPopoverControllerDidDismissNotification";
  13.  
  14. @implementation LRPopoverManager
  15.  
  16. @synthesize currentPopoverController;
  17. @synthesize permitCurrentPopoverControllerToDismiss;
  18.  
  19. static LRPopoverManager *sharedManager = nil;
  20.  
  21. + (void)initialize {
  22. if (self == [LRPopoverManager class]) {
  23. sharedManager = [[self alloc] init];
  24. sharedManager.permitCurrentPopoverControllerToDismiss = YES;
  25. }
  26. }
  27.  
  28. + (id)sharedManager {
  29. return sharedManager;
  30. }
  31.  
  32. - (void)setCurrentPopoverController:(UIPopoverController *)pc
  33. {
  34. [self dismissCurrentPopoverController:YES];
  35.  
  36. if (pc != currentPopoverController) {
  37. [currentPopoverController release];
  38. currentPopoverController = [pc retain];
  39. currentPopoverController.delegate = self;
  40. }
  41. self.permitCurrentPopoverControllerToDismiss = YES;
  42. }
  43.  
  44. - (void)presentPopoverController:(UIPopoverController *)pc fromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
  45. {
  46. self.currentPopoverController = pc;
  47. [self.currentPopoverController presentPopoverFromRect:rect inView:view permittedArrowDirections:arrowDirections animated:animated];
  48. }
  49.  
  50. - (void)presentPopoverController:(UIPopoverController *)pc fromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
  51. {
  52. self.currentPopoverController = pc;
  53. [self.currentPopoverController presentPopoverFromBarButtonItem:item permittedArrowDirections:arrowDirections animated:animated];
  54. }
  55.  
  56. - (void)dismissCurrentPopoverController:(BOOL)animated;
  57. {
  58. [self.currentPopoverController dismissPopoverAnimated:animated];
  59. }
  60.  
  61. - (void)presentControllerInPopoverController:(UIViewController *)vc fromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
  62. {
  63. UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];
  64. [self presentPopoverController:pc fromRect:rect inView:view permittedArrowDirections:arrowDirections animated:animated];
  65. [pc release];
  66. }
  67.  
  68. - (void)presentControllerInPopoverController:(UIViewController *)vc fromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
  69. {
  70. UIPopoverController *pc = [[UIPopoverController alloc] initWithContentViewController:vc];
  71. [self presentPopoverController:pc fromBarButtonItem:item permittedArrowDirections:arrowDirections animated:animated];
  72. [pc release];
  73. }
  74.  
  75. #pragma mark -
  76. #pragma mark UIPopoverControllerDelegate methods
  77.  
  78. - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
  79. {
  80. [[NSNotificationCenter defaultCenter] postNotificationName:LRUIPopoverControllerDidDismissNotification object:popoverController];
  81. }
  82.  
  83. - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
  84. {
  85. return self.permitCurrentPopoverControllerToDismiss;
  86. }
  87.  
  88. @end
Add Comment
Please, Sign In to add comment