PopoverView.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // PopoverView.h
  3. // Embark
  4. //
  5. // Created by Oliver Rickard on 20/08/2012.
  6. //
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "PopoverViewCompatibility.h"
  10. /**************** Support both ARC and non-ARC ********************/
  11. #ifndef SUPPORT_ARC
  12. #define SUPPORT_ARC
  13. #if __has_feature(objc_arc_weak) //objc_arc_weak
  14. #define WEAK weak
  15. #define __WEAK __weak
  16. #define STRONG strong
  17. #define AUTORELEASE self
  18. #define RELEASE self
  19. #define RETAIN self
  20. #define CFTYPECAST(exp) (__bridge exp)
  21. #define TYPECAST(exp) (__bridge_transfer exp)
  22. #define CFRELEASE(exp) CFRelease(exp)
  23. #define DEALLOC self
  24. #elif __has_feature(objc_arc) //objc_arc
  25. #define WEAK unsafe_unretained
  26. #define __WEAK __unsafe_unretained
  27. #define STRONG strong
  28. #define AUTORELEASE self
  29. #define RELEASE self
  30. #define RETAIN self
  31. #define CFTYPECAST(exp) (__bridge exp)
  32. #define TYPECAST(exp) (__bridge_transfer exp)
  33. #define CFRELEASE(exp) CFRelease(exp)
  34. #define DEALLOC self
  35. #else //none
  36. #define WEAK assign
  37. #define __WEAK
  38. #define STRONG retain
  39. #define AUTORELEASE autorelease
  40. #define RELEASE release
  41. #define RETAIN retain
  42. #define CFTYPECAST(exp) (exp)
  43. #define TYPECAST(exp) (exp)
  44. #define CFRELEASE(exp) CFRelease(exp)
  45. #define DEALLOC dealloc
  46. #endif
  47. #endif
  48. /******************************************************************/
  49. @class PopoverView;
  50. @protocol PopoverViewDelegate <NSObject>
  51. @optional
  52. //Delegate receives this call as soon as the item has been selected
  53. - (void)popoverView:(PopoverView *)popoverView didSelectItemAtIndex:(NSInteger)index;
  54. //Delegate receives this call once the popover has begun the dismissal animation
  55. - (void)popoverViewDidDismiss:(PopoverView *)popoverView;
  56. @end
  57. @interface PopoverView : UIView {
  58. CGRect boxFrame;
  59. CGSize contentSize;
  60. CGPoint arrowPoint;
  61. BOOL above;
  62. __WEAK id<PopoverViewDelegate> delegate;
  63. UIView *parentView;
  64. UIView *topView;
  65. NSArray *subviewsArray;
  66. NSArray *dividerRects;
  67. UIView *contentView;
  68. UIView *titleView;
  69. UIActivityIndicatorView *activityIndicator;
  70. //Instance variable that can change at runtime
  71. BOOL showDividerRects;
  72. }
  73. @property (nonatomic, STRONG) UIView *titleView;
  74. @property (nonatomic, STRONG) UIView *contentView;
  75. @property (nonatomic, STRONG) NSArray *subviewsArray;
  76. @property (nonatomic, WEAK) id<PopoverViewDelegate> delegate;
  77. #pragma mark - Class Static Showing Methods
  78. //These are the main static methods you can use to display the popover.
  79. //Simply call [PopoverView show...] with your arguments, and the popover will be generated, added to the view stack, and notify you when it's done.
  80. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withText:(NSString *)text delegate:(id<PopoverViewDelegate>)delegate;
  81. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withText:(NSString *)text delegate:(id<PopoverViewDelegate>)delegate;
  82. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withViewArray:(NSArray *)viewArray delegate:(id<PopoverViewDelegate>)delegate;
  83. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withViewArray:(NSArray *)viewArray delegate:(id<PopoverViewDelegate>)delegate;
  84. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray delegate:(id<PopoverViewDelegate>)delegate;
  85. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withStringArray:(NSArray *)stringArray delegate:(id<PopoverViewDelegate>)delegate;
  86. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray withImageArray:(NSArray *)imageArray delegate:(id<PopoverViewDelegate>)delegate;
  87. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withStringArray:(NSArray *)stringArray withImageArray:(NSArray *)imageArray delegate:(id<PopoverViewDelegate>)delegate;
  88. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withContentView:(UIView *)cView delegate:(id<PopoverViewDelegate>)delegate;
  89. + (PopoverView *)showPopoverAtPoint:(CGPoint)point inView:(UIView *)view withContentView:(UIView *)cView delegate:(id<PopoverViewDelegate>)delegate;
  90. #pragma mark - Instance Showing Methods
  91. //Adds/animates in the popover to the top of the view stack with the arrow pointing at the "point"
  92. //within the specified view. The contentView will be added to the popover, and should have either
  93. //a clear color backgroundColor, or perhaps a rounded corner bg rect (radius 4.f if you're going to
  94. //round).
  95. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withContentView:(UIView *)contentView;
  96. //Calls above method with a UILabel containing the text you deliver to this method.
  97. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withText:(NSString *)text;
  98. //Calls top method with an array of UIView objects. This method will stack these views vertically
  99. //with kBoxPadding padding between each view in the y-direction.
  100. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withViewArray:(NSArray *)viewArray;
  101. //Does same as above, but adds a title label at top of the popover.
  102. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withViewArray:(NSArray *)viewArray;
  103. //Calls the viewArray method with an array of UILabels created with the strings
  104. //in stringArray. All contents of stringArray must be NSStrings.
  105. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray;
  106. //This method does same as above, but with a title label at the top of the popover.
  107. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withStringArray:(NSArray *)stringArray;
  108. //Draws a vertical list of the NSString elements of stringArray with UIImages
  109. //from imageArray placed centered above them.
  110. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withStringArray:(NSArray *)stringArray withImageArray:(NSArray *)imageArray;
  111. //Does the same as above, but with a title
  112. - (void)showAtPoint:(CGPoint)point inView:(UIView *)view withTitle:(NSString *)title withStringArray:(NSArray *)stringArray withImageArray:(NSArray *)imageArray;
  113. //Lays out the PopoverView at a point once all of the views have already been setup elsewhere
  114. - (void)layoutAtPoint:(CGPoint)point inView:(UIView *)view;
  115. #pragma mark - Other Interaction
  116. //This method animates the rotation of the PopoverView to a new point
  117. - (void)animateRotationToNewPoint:(CGPoint)point inView:(UIView *)view withDuration:(NSTimeInterval)duration;
  118. #pragma mark - Dismissal
  119. //Dismisses the view, and removes it from the view stack.
  120. - (void)dismiss;
  121. - (void)dismiss:(BOOL)animated;
  122. #pragma mark - Activity Indicator Methods
  123. //Shows the activity indicator, and changes the title (if the title is available, and is a UILabel).
  124. - (void)showActivityIndicatorWithMessage:(NSString *)msg;
  125. //Hides the activity indicator, and changes the title (if the title is available) to the msg
  126. - (void)hideActivityIndicatorWithMessage:(NSString *)msg;
  127. #pragma mark - Custom Image Showing
  128. //Animate in, and display the image provided here.
  129. - (void)showImage:(UIImage *)image withMessage:(NSString *)msg;
  130. #pragma mark - Error/Success Methods
  131. //Shows (and animates in) an error X in the contentView
  132. - (void)showError;
  133. //Shows (and animates in) a success checkmark in the contentView
  134. - (void)showSuccess;
  135. @end