WYPopoverController.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. Version 0.3.9
  3. WYPopoverController is available under the MIT license.
  4. Copyright © 2013 Nicolas CHENG
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included
  12. in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  14. INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15. PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  16. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  18. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. #import <Foundation/Foundation.h>
  21. #import <UIKit/UIKit.h>
  22. #import <QuartzCore/QuartzCore.h>
  23. @protocol WYPopoverControllerDelegate;
  24. @class WYPopoverTheme;
  25. #ifndef WY_POPOVER_DEFAULT_ANIMATION_DURATION
  26. #define WY_POPOVER_DEFAULT_ANIMATION_DURATION .25f
  27. #endif
  28. #ifndef WY_POPOVER_MIN_SIZE
  29. #define WY_POPOVER_MIN_SIZE CGSizeMake(240, 160)
  30. #endif
  31. typedef NS_OPTIONS(NSUInteger, WYPopoverArrowDirection) {
  32. WYPopoverArrowDirectionUp = 1UL << 0,
  33. WYPopoverArrowDirectionDown = 1UL << 1,
  34. WYPopoverArrowDirectionLeft = 1UL << 2,
  35. WYPopoverArrowDirectionRight = 1UL << 3,
  36. WYPopoverArrowDirectionNone = 1UL << 4,
  37. WYPopoverArrowDirectionAny = WYPopoverArrowDirectionUp | WYPopoverArrowDirectionDown | WYPopoverArrowDirectionLeft | WYPopoverArrowDirectionRight,
  38. WYPopoverArrowDirectionUnknown = NSUIntegerMax
  39. };
  40. typedef NS_OPTIONS(NSUInteger, WYPopoverAnimationOptions) {
  41. WYPopoverAnimationOptionFade = 1UL << 0, // default
  42. WYPopoverAnimationOptionScale = 1UL << 1,
  43. WYPopoverAnimationOptionFadeWithScale = WYPopoverAnimationOptionFade | WYPopoverAnimationOptionScale
  44. };
  45. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  46. @interface WYPopoverBackgroundView : UIView
  47. // UI_APPEARANCE_SELECTOR doesn't support BOOLs on iOS 7,
  48. // so these two need to be NSUInteger instead
  49. @property (nonatomic, assign) NSUInteger usesRoundedArrow UI_APPEARANCE_SELECTOR;
  50. @property (nonatomic, assign) NSUInteger dimsBackgroundViewsTintColor UI_APPEARANCE_SELECTOR;
  51. @property (nonatomic, strong) UIColor *tintColor UI_APPEARANCE_SELECTOR;
  52. @property (nonatomic, strong) UIColor *fillTopColor UI_APPEARANCE_SELECTOR;
  53. @property (nonatomic, strong) UIColor *fillBottomColor UI_APPEARANCE_SELECTOR;
  54. @property (nonatomic, strong) UIColor *glossShadowColor UI_APPEARANCE_SELECTOR;
  55. @property (nonatomic, assign) CGSize glossShadowOffset UI_APPEARANCE_SELECTOR;
  56. @property (nonatomic, assign) NSUInteger glossShadowBlurRadius UI_APPEARANCE_SELECTOR;
  57. @property (nonatomic, assign) NSUInteger borderWidth UI_APPEARANCE_SELECTOR;
  58. @property (nonatomic, assign) NSUInteger arrowBase UI_APPEARANCE_SELECTOR;
  59. @property (nonatomic, assign) NSUInteger arrowHeight UI_APPEARANCE_SELECTOR;
  60. @property (nonatomic, strong) UIColor *outerShadowColor UI_APPEARANCE_SELECTOR;
  61. @property (nonatomic, strong) UIColor *outerStrokeColor UI_APPEARANCE_SELECTOR;
  62. @property (nonatomic, assign) NSUInteger outerShadowBlurRadius UI_APPEARANCE_SELECTOR;
  63. @property (nonatomic, assign) CGSize outerShadowOffset UI_APPEARANCE_SELECTOR;
  64. @property (nonatomic, assign) NSUInteger outerCornerRadius UI_APPEARANCE_SELECTOR;
  65. @property (nonatomic, assign) NSUInteger minOuterCornerRadius UI_APPEARANCE_SELECTOR;
  66. @property (nonatomic, strong) UIColor *innerShadowColor UI_APPEARANCE_SELECTOR;
  67. @property (nonatomic, strong) UIColor *innerStrokeColor UI_APPEARANCE_SELECTOR;
  68. @property (nonatomic, assign) NSUInteger innerShadowBlurRadius UI_APPEARANCE_SELECTOR;
  69. @property (nonatomic, assign) CGSize innerShadowOffset UI_APPEARANCE_SELECTOR;
  70. @property (nonatomic, assign) NSUInteger innerCornerRadius UI_APPEARANCE_SELECTOR;
  71. @property (nonatomic, assign) UIEdgeInsets viewContentInsets UI_APPEARANCE_SELECTOR;
  72. @property (nonatomic, strong) UIColor *overlayColor UI_APPEARANCE_SELECTOR;
  73. @property(nonatomic) CGFloat preferredAlpha UI_APPEARANCE_SELECTOR;
  74. @end
  75. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  76. @interface WYPopoverController : NSObject <UIAppearanceContainer>
  77. @property (nonatomic, weak) id <WYPopoverControllerDelegate> delegate;
  78. @property (nonatomic, assign) BOOL dismissOnTap;
  79. @property (nonatomic, copy) NSArray *passthroughViews;
  80. @property (nonatomic, assign) BOOL dismissOnPassthroughViewTap;
  81. @property (nonatomic, assign) BOOL wantsDefaultContentAppearance;
  82. @property (nonatomic, assign) UIEdgeInsets popoverLayoutMargins;
  83. @property (nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible;
  84. @property (nonatomic, strong, readonly) UIViewController *contentViewController;
  85. @property (nonatomic, assign) CGSize popoverContentSize;
  86. @property (nonatomic, assign) float animationDuration;
  87. @property (nonatomic, assign) BOOL implicitAnimationsDisabled;
  88. @property (nonatomic, strong) WYPopoverTheme *theme;
  89. @property (nonatomic, copy) void (^dismissCompletionBlock)(WYPopoverController *dimissedController);
  90. + (void)setDefaultTheme:(WYPopoverTheme *)theme;
  91. + (WYPopoverTheme *)defaultTheme;
  92. // initialization
  93. - (id)initWithContentViewController:(UIViewController *)viewController;
  94. // theme
  95. - (void)beginThemeUpdates;
  96. - (void)endThemeUpdates;
  97. // Present popover from classic views methods
  98. - (void)presentPopoverFromRect:(CGRect)rect
  99. inView:(UIView *)view
  100. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  101. animated:(BOOL)animated;
  102. - (void)presentPopoverFromRect:(CGRect)rect
  103. inView:(UIView *)view
  104. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  105. animated:(BOOL)animated
  106. completion:(void (^)(void))completion;
  107. - (void)presentPopoverFromRect:(CGRect)rect
  108. inView:(UIView *)view
  109. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  110. animated:(BOOL)animated
  111. options:(WYPopoverAnimationOptions)options;
  112. - (void)presentPopoverFromRect:(CGRect)rect
  113. inView:(UIView *)view
  114. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  115. animated:(BOOL)animated
  116. options:(WYPopoverAnimationOptions)options
  117. completion:(void (^)(void))completion;
  118. // Present popover from bar button items methods
  119. - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
  120. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  121. animated:(BOOL)animated;
  122. - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
  123. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  124. animated:(BOOL)animated
  125. completion:(void (^)(void))completion;
  126. - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
  127. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  128. animated:(BOOL)animated
  129. options:(WYPopoverAnimationOptions)options;
  130. - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
  131. permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections
  132. animated:(BOOL)animated
  133. options:(WYPopoverAnimationOptions)options
  134. completion:(void (^)(void))completion;
  135. // Present popover as dialog methods
  136. - (void)presentPopoverAsDialogAnimated:(BOOL)animated;
  137. - (void)presentPopoverAsDialogAnimated:(BOOL)animated
  138. completion:(void (^)(void))completion;
  139. - (void)presentPopoverAsDialogAnimated:(BOOL)animated
  140. options:(WYPopoverAnimationOptions)options;
  141. - (void)presentPopoverAsDialogAnimated:(BOOL)animated
  142. options:(WYPopoverAnimationOptions)options
  143. completion:(void (^)(void))completion;
  144. // Dismiss popover methods
  145. - (void)dismissPopoverAnimated:(BOOL)animated;
  146. - (void)dismissPopoverAnimated:(BOOL)animated
  147. completion:(void (^)(void))completion;
  148. - (void)dismissPopoverAnimated:(BOOL)animated
  149. options:(WYPopoverAnimationOptions)aOptions;
  150. - (void)dismissPopoverAnimated:(BOOL)animated
  151. options:(WYPopoverAnimationOptions)aOptions
  152. completion:(void (^)(void))completion;
  153. // Misc
  154. - (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated;
  155. - (void)performWithoutAnimation:(void (^)(void))aBlock;
  156. @end
  157. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  158. @protocol WYPopoverControllerDelegate <NSObject>
  159. @optional
  160. - (BOOL)popoverControllerShouldDismissPopover:(WYPopoverController *)popoverController;
  161. - (void)popoverControllerDidPresentPopover:(WYPopoverController *)popoverController;
  162. - (void)popoverControllerDidDismissPopover:(WYPopoverController *)popoverController;
  163. - (void)popoverController:(WYPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView **)view;
  164. - (BOOL)popoverControllerShouldIgnoreKeyboardBounds:(WYPopoverController *)popoverController;
  165. - (void)popoverController:(WYPopoverController *)popoverController willTranslatePopoverWithYOffset:(float *)value;
  166. @end
  167. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  168. @interface WYPopoverTheme : NSObject
  169. // These two can be BOOLs, because implicit casting
  170. // between BOOLs and NSUIntegers works fine
  171. @property (nonatomic, assign) BOOL usesRoundedArrow;
  172. @property (nonatomic, assign) BOOL dimsBackgroundViewsTintColor;
  173. @property (nonatomic, strong) UIColor *tintColor;
  174. @property (nonatomic, strong) UIColor *fillTopColor;
  175. @property (nonatomic, strong) UIColor *fillBottomColor;
  176. @property (nonatomic, strong) UIColor *glossShadowColor;
  177. @property (nonatomic, assign) CGSize glossShadowOffset;
  178. @property (nonatomic, assign) NSUInteger glossShadowBlurRadius;
  179. @property (nonatomic, assign) NSUInteger borderWidth;
  180. @property (nonatomic, assign) NSUInteger arrowBase;
  181. @property (nonatomic, assign) NSUInteger arrowHeight;
  182. @property (nonatomic, strong) UIColor *outerShadowColor;
  183. @property (nonatomic, strong) UIColor *outerStrokeColor;
  184. @property (nonatomic, assign) NSUInteger outerShadowBlurRadius;
  185. @property (nonatomic, assign) CGSize outerShadowOffset;
  186. @property (nonatomic, assign) NSUInteger outerCornerRadius;
  187. @property (nonatomic, assign) NSUInteger minOuterCornerRadius;
  188. @property (nonatomic, strong) UIColor *innerShadowColor;
  189. @property (nonatomic, strong) UIColor *innerStrokeColor;
  190. @property (nonatomic, assign) NSUInteger innerShadowBlurRadius;
  191. @property (nonatomic, assign) CGSize innerShadowOffset;
  192. @property (nonatomic, assign) NSUInteger innerCornerRadius;
  193. @property (nonatomic, assign) UIEdgeInsets viewContentInsets;
  194. @property (nonatomic, strong) UIColor *overlayColor;
  195. @property (nonatomic) CGFloat preferredAlpha;
  196. + (instancetype)theme;
  197. + (instancetype)themeForIOS6;
  198. + (instancetype)themeForIOS7;
  199. @end