RATreeView.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //The MIT License (MIT)
  2. //
  3. //Copyright (c) 2013 Rafał Augustyniak
  4. //
  5. //Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. //this software and associated documentation files (the "Software"), to deal in
  7. //the Software without restriction, including without limitation the rights to
  8. //use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. //the Software, and to permit persons to whom the Software is furnished to do so,
  10. //subject to the following conditions:
  11. //
  12. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. //FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. //COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. //IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. //CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. //
  19. #import <UIKit/UIKit.h>
  20. #import "RATreeNodeInfo.h"
  21. @class RATreeView;
  22. @class RATreeViewCell;
  23. @class RATreeNodeInfo;
  24. @class RATreeNodeCollectionController;
  25. @class RATreeNode;
  26. typedef enum {
  27. RATreeViewStylePlain = 0,
  28. RATreeViewStyleGrouped
  29. } RATreeViewStyle;
  30. typedef enum RATreeViewCellSeparatorStyle {
  31. RATreeViewCellSeparatorStyleNone = 0,
  32. RATreeViewCellSeparatorStyleSingleLine
  33. // ,
  34. // RATreeViewCellSeparatorStyleSingleLineEtched
  35. } RATreeViewCellSeparatorStyle;
  36. typedef enum RATreeViewScrollPosition {
  37. RATreeViewScrollPositionNone = 0,
  38. RATreeViewScrollPositionTop,
  39. RATreeViewScrollPositionMiddle,
  40. RATreeViewScrollPositionBottom
  41. } RATreeViewScrollPosition;
  42. typedef enum RATreeViewRowAnimation {
  43. RATreeViewRowAnimationNone = 0,
  44. RATreeViewRowAnimationRight,
  45. RATreeViewRowAnimationLeft,
  46. RATreeViewRowAnimationTop,
  47. RATreeViewRowAnimationBottom,
  48. RATreeViewRowAnimationMiddle,
  49. RATreeViewRowAnimationAutomatic
  50. } RATreeViewRowAnimation;
  51. @protocol RATreeViewDataSource <NSObject>
  52. @required
  53. - (NSInteger)treeView:(RATreeView *)treeView numberOfChildrenOfItem:(id)item;
  54. - (UITableViewCell *)treeView:(RATreeView *)treeView cellForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  55. - (id)treeView:(RATreeView *)treeView child:(NSInteger)index ofItem:(id)item;
  56. @optional
  57. //Inserting or Deleting Table Rows
  58. - (void)treeView:(RATreeView *)treeView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  59. - (BOOL)treeView:(RATreeView *)treeView canEditRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  60. @end
  61. @protocol RATreeViewDelegate <NSObject, UIScrollViewDelegate>
  62. @optional
  63. // Configuring Rows for the Table View
  64. - (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  65. - (CGFloat)treeView:(RATreeView *)treeView estimatedHeightForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo NS_AVAILABLE_IOS(7_0);
  66. - (NSInteger)treeView:(RATreeView *)treeView indentationLevelForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  67. - (void)treeView:(RATreeView *)treeView willDisplayCell:(UITableViewCell *)cell forItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  68. // Managin Accessory Views
  69. - (void)treeView:(RATreeView *)treeView accessoryButtonTappedForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  70. //Expanding and Collapsing the Outline
  71. - (BOOL)treeView:(RATreeView *)treeView shouldItemBeExpandedAfterDataReload:(id)item treeDepthLevel:(NSInteger)treeDepthLevel;
  72. - (BOOL)treeView:(RATreeView *)treeView shouldExpandRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  73. - (BOOL)treeView:(RATreeView *)treeView shouldCollapaseRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  74. - (void)treeView:(RATreeView *)treeView willExpandRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  75. - (void)treeView:(RATreeView *)treeView willCollapseRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  76. - (void)treeView:(RATreeView *)treeView didExpandRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  77. - (void)treeView:(RATreeView *)treeView didCollapseRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  78. //Managing Selections
  79. - (id)treeView:(RATreeView *)treeView willSelectRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  80. - (void)treeView:(RATreeView *)treeView didSelectRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  81. - (id)treeView:(RATreeView *)treeView willDeselectRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  82. - (void)treeView:(RATreeView *)treeView didDeselectRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  83. //Editing Tree Rows
  84. - (void)treeView:(RATreeView *)treeView willBeginEditingRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  85. - (void)treeView:(RATreeView *)treeView didEndEditingRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  86. - (UITableViewCellEditingStyle)treeView:(RATreeView *)treeView editingStyleForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  87. - (NSString *)treeView:(RATreeView *)treeView titleForDeleteConfirmationButtonForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  88. - (BOOL)treeView:(RATreeView *)treeView shouldIndentWhileEditingRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  89. //Tracking the Removal of Views
  90. - (void)treeView:(RATreeView *)treeView didEndDisplayingCell:(RATreeViewCell *)cell forItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  91. ////Copying and Pasting Row Content
  92. //- (BOOL)treeView:(RATreeView *)treeView shouldShowMenuForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  93. //- (BOOL)treeView:(RATreeView *)treeView canPerformAction:(SEL)action forRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo withSender:(id)sender;
  94. //- (void)treeView:(RATreeView *)treeView performAction:(SEL)action forRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo withSender:(id)sender;
  95. //Managing Table View Highlighting
  96. - (BOOL)treeView:(RATreeView *)treeView shouldHighlightRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  97. - (BOOL)treeView:(RATreeView *)treeView didHighlightRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  98. - (BOOL)treeView:(RATreeView *)treeView didUnhighlightRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;
  99. @end
  100. @interface RATreeView : UIView
  101. @property (weak, nonatomic) id<RATreeViewDataSource> dataSource;
  102. @property (weak, nonatomic) id<RATreeViewDelegate> delegate;
  103. // Initializing a TreeView Object
  104. - (id)initWithFrame:(CGRect)frame style:(RATreeViewStyle)style;
  105. //Configuring a Tree View
  106. - (NSInteger)numberOfRows;
  107. @property (nonatomic, readonly) RATreeViewStyle style;
  108. @property (nonatomic) RATreeViewCellSeparatorStyle separatorStyle;
  109. @property (strong, nonatomic) UIColor *separatorColor;
  110. @property (nonatomic) CGFloat rowHeight;
  111. @property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0);
  112. @property (nonatomic) UIEdgeInsets separatorInset NS_AVAILABLE_IOS(7_0);
  113. @property (strong, nonatomic) UIView *backgroundView;
  114. //Expanding and Collapsing Rows
  115. - (void)expandRowForItem:(id)item withRowAnimation:(RATreeViewRowAnimation)animation;
  116. - (void)collapseRowForItem:(id)item withRowAnimation:(RATreeViewRowAnimation)animation;
  117. - (void)expandRowForItem:(id)item;
  118. - (void)collapseRowForItem:(id)item;
  119. @property (nonatomic) RATreeViewRowAnimation rowsExpandingAnimation;
  120. @property (nonatomic) RATreeViewRowAnimation rowsCollapsingAnimation;
  121. // Creating Table View Cells
  122. - (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
  123. - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier;
  124. - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier;
  125. // Accessing Header and Footer Views
  126. - (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
  127. - (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
  128. - (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
  129. @property (strong, nonatomic) UIView *treeHeaderView;
  130. @property (strong, nonatomic) UIView *treeFooterView;
  131. // Accessing Cells
  132. - (UITableViewCell *)cellForItem:(id)item;
  133. - (NSArray *)visibleCells;
  134. // Scrolling the TreeView
  135. - (void)scrollToRowForItem:(id)item atScrollPosition:(RATreeViewScrollPosition)scrollPosition animated:(BOOL)animated;
  136. - (void)scrollToNearestSelectedRowAtScrollPosition:(RATreeViewScrollPosition)scrollPosition animated:(BOOL)animated;
  137. // Managing Selections
  138. - (id)itemForSelectedRow;
  139. - (NSArray *)itemsForSelectedRows;
  140. - (void)selectRowForItem:(id)item animated:(BOOL)animated scrollPosition:(RATreeViewScrollPosition)scrollPosition;
  141. - (void)deselectRowForItem:(id)item animated:(BOOL)animated;
  142. @property (nonatomic) BOOL allowsSelection;
  143. @property (nonatomic) BOOL allowsMultipleSelection;
  144. @property (nonatomic) BOOL allowsSelectionDuringEditing;
  145. @property (nonatomic) BOOL allowsMultipleSelectionDuringEditing;
  146. // Managing the Editing of Tree Cells
  147. - (void)setEditing:(BOOL)editing animated:(BOOL)animated;
  148. @property (nonatomic, getter = isEditing) BOOL editing;
  149. // Reloading the Tree View
  150. - (void)reloadData;
  151. - (void)reloadRowsForItems:(NSArray *)items withRowAnimation:(RATreeViewRowAnimation)animation;
  152. - (void)reloadRows;
  153. /////////////////////////////
  154. // UIScrollView Staff
  155. /////////////////////////////
  156. //Managing the Display of Content
  157. - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;
  158. @property (nonatomic) CGPoint contentOffset;
  159. @property (nonatomic) CGSize contentSize;
  160. @property (nonatomic) UIEdgeInsets contentInset;
  161. //Managing Scrolling
  162. @property (nonatomic) BOOL scrollEnabled;
  163. @property (nonatomic) BOOL directionalLockEnabled;
  164. @property (nonatomic) BOOL scrollsToTop;
  165. - (void)scrollRectToVisible:(CGRect)visible animated:(BOOL)animated;
  166. @property (nonatomic) BOOL pagingEnabled;
  167. @property (nonatomic) BOOL bounces;
  168. @property (nonatomic) BOOL alwaysBounceVertical;
  169. @property (nonatomic) BOOL alwaysBounceHorizontal;
  170. @property (nonatomic) BOOL canCancelContentTouches;
  171. @property (nonatomic) BOOL delaysContentTouches;
  172. @property (nonatomic) BOOL decelerationRate;
  173. @property (nonatomic, readonly) BOOL dragging;
  174. @property (nonatomic, readonly) BOOL tracking;
  175. @property (nonatomic, readonly) BOOL decelerating;
  176. //Managing the Scroll Indicator
  177. @property (nonatomic) UIScrollViewIndicatorStyle indicatorStyle;
  178. @property (nonatomic) UIEdgeInsets scrollIndicatorInsets;
  179. @property (nonatomic) BOOL showsHorizontalScrollIndicator;
  180. @property (nonatomic) BOOL showsVerticalScrollIndicator;
  181. - (void)flashScrollIndicators;
  182. //Zooming and Panning
  183. @property (strong, nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer;
  184. @property (strong, nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer;
  185. - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated;
  186. @property (nonatomic) CGFloat zoomScale;
  187. - (void)setZoomScale:(CGFloat)zoomScale animated:(BOOL)animated;
  188. @property (nonatomic) CGFloat maximumZoomScale;
  189. @property (nonatomic) CGFloat minimumZoomScale;
  190. @property (nonatomic, readonly) BOOL zoomBouncing;
  191. @property (nonatomic, readonly) BOOL zooming;
  192. @property (nonatomic) BOOL bouncesZoom;
  193. @end