RATreeView+UIScrollView.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 "RATreeView+UIScrollView.h"
  20. #import "RATreeView+Private.h"
  21. @implementation RATreeView (UIScrollView)
  22. #pragma clang diagnostic push
  23. #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
  24. #pragma mark Managing the Display of Content
  25. - (void)setContentOffset:(CGPoint)contentOffset
  26. {
  27. self.tableView.contentOffset = contentOffset;
  28. }
  29. - (CGPoint)contentOffset
  30. {
  31. return self.tableView.contentOffset;
  32. }
  33. - (void)setContentSize:(CGSize)contentSize
  34. {
  35. self.tableView.contentSize = contentSize;
  36. }
  37. - (CGSize)contentSize
  38. {
  39. return self.tableView.contentSize;
  40. }
  41. - (void)setContentInset:(UIEdgeInsets)contentInset
  42. {
  43. self.tableView.contentInset = contentInset;
  44. }
  45. - (UIEdgeInsets)contentInset
  46. {
  47. return self.tableView.contentInset;
  48. }
  49. #pragma mark Managing Scrolling
  50. - (void)setScrollEnabled:(BOOL)scrollEnabled
  51. {
  52. self.tableView.scrollEnabled = scrollEnabled;
  53. }
  54. - (BOOL)scrollEnabled
  55. {
  56. return self.tableView.scrollEnabled;
  57. }
  58. - (void)setDirectionalLockEnabled:(BOOL)directionalLockEnabled
  59. {
  60. self.tableView.directionalLockEnabled = directionalLockEnabled;
  61. }
  62. - (BOOL)directionalLockEnabled
  63. {
  64. return self.tableView.directionalLockEnabled;
  65. }
  66. - (void)setScrollsToTop:(BOOL)scrollsToTop
  67. {
  68. self.tableView.scrollsToTop = scrollsToTop;
  69. }
  70. -(BOOL)scrollsToTop
  71. {
  72. return self.tableView.scrollsToTop;
  73. }
  74. - (void)setPagingEnabled:(BOOL)pagingEnabled
  75. {
  76. self.tableView.pagingEnabled = pagingEnabled;
  77. }
  78. - (BOOL)pagingEnabled
  79. {
  80. return self.tableView.pagingEnabled;
  81. }
  82. - (void)setBounces:(BOOL)bounces
  83. {
  84. self.tableView.bounces = bounces;
  85. }
  86. - (BOOL)bounces
  87. {
  88. return self.tableView.bounces;
  89. }
  90. - (void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical
  91. {
  92. self.tableView.alwaysBounceVertical = alwaysBounceVertical;
  93. }
  94. - (BOOL)alwaysBounceVertical
  95. {
  96. return self.tableView.alwaysBounceVertical;
  97. }
  98. - (void)setAlwaysBounceHorizontal:(BOOL)alwaysBounceHorizontal
  99. {
  100. self.tableView.alwaysBounceHorizontal = alwaysBounceHorizontal;
  101. }
  102. - (BOOL)alwaysBounceHorizontal
  103. {
  104. return self.tableView.alwaysBounceHorizontal;
  105. }
  106. - (void)setCanCancelContentTouches:(BOOL)canCancelContentTouches
  107. {
  108. self.tableView.canCancelContentTouches = canCancelContentTouches;
  109. }
  110. - (BOOL)canCancelContentTouches
  111. {
  112. return self.tableView.canCancelContentTouches;
  113. }
  114. - (void)setDelaysContentTouches:(BOOL)delaysContentTouches
  115. {
  116. self.tableView.delaysContentTouches = delaysContentTouches;
  117. }
  118. - (BOOL)delaysContentTouches
  119. {
  120. return self.tableView.delaysContentTouches;
  121. }
  122. - (void)setDecelerationRate:(BOOL)decelerationRate
  123. {
  124. self.tableView.decelerationRate = decelerationRate;
  125. }
  126. - (BOOL)decelerationRate
  127. {
  128. return self.tableView.decelerationRate;
  129. }
  130. - (BOOL)dragging
  131. {
  132. return self.tableView.dragging;
  133. }
  134. - (BOOL)tracking
  135. {
  136. return self.tableView.tracking;
  137. }
  138. - (BOOL)decelerating
  139. {
  140. return self.tableView.decelerating;
  141. }
  142. #pragma mark Managin the Scroll Indicator
  143. - (void)setIndicatorStyle:(UIScrollViewIndicatorStyle)indicatorStyle
  144. {
  145. self.tableView.indicatorStyle = indicatorStyle;
  146. }
  147. - (UIScrollViewIndicatorStyle)indicatorStyle
  148. {
  149. return self.tableView.indicatorStyle;
  150. }
  151. //
  152. //- (void)setScrollIndicatorInsets:(UIEdgeInsets)scrollIndicatorInsets
  153. //{
  154. // self.tableView.scrollIndicatorInsets = scrollIndicatorInsets;
  155. //}
  156. //
  157. //- (UIEdgeInsets)scrollIndicatorInsets
  158. //{
  159. // return self.tableView.scrollIndicatorInsets;
  160. //}
  161. - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
  162. {
  163. self.tableView.showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;
  164. }
  165. - (BOOL)showsHorizontalScrollIndicator
  166. {
  167. return self.tableView.showsHorizontalScrollIndicator;
  168. }
  169. - (void)setShowsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator
  170. {
  171. self.tableView.showsVerticalScrollIndicator = showsVerticalScrollIndicator;
  172. }
  173. - (BOOL)showsVerticalScrollIndicator
  174. {
  175. return self.tableView.showsVerticalScrollIndicator;
  176. }
  177. #pragma mark Zooming and Panning
  178. - (UIPanGestureRecognizer *)panGestureRecognizer
  179. {
  180. return self.panGestureRecognizer;
  181. }
  182. - (UIPinchGestureRecognizer *)pinchGestureRecognizer
  183. {
  184. return self.pinchGestureRecognizer;
  185. }
  186. - (void)setZoomScale:(CGFloat)zoomScale
  187. {
  188. self.tableView.zoomScale = zoomScale;
  189. }
  190. - (CGFloat)zoomScale
  191. {
  192. return self.tableView.zoomScale;
  193. }
  194. - (void)setMaximumZoomScale:(CGFloat)maximumZoomScale
  195. {
  196. self.tableView.maximumZoomScale = maximumZoomScale;
  197. }
  198. - (CGFloat)maximumZoomScale
  199. {
  200. return self.tableView.maximumZoomScale;
  201. }
  202. - (void)setMinimumZoomScale:(CGFloat)minimumZoomScale
  203. {
  204. self.tableView.minimumZoomScale = minimumZoomScale;
  205. }
  206. - (CGFloat)minimumZoomScale
  207. {
  208. return self.tableView.minimumZoomScale;
  209. }
  210. - (BOOL)zoomBouncing
  211. {
  212. return self.tableView.zoomBouncing;
  213. }
  214. - (BOOL)zooming
  215. {
  216. return self.tableView.zooming;
  217. }
  218. - (void)setBouncesZoom:(BOOL)bouncesZoom
  219. {
  220. self.tableView.bouncesZoom = bouncesZoom;
  221. }
  222. - (BOOL)bouncesZoom
  223. {
  224. return self.tableView.bouncesZoom;
  225. }
  226. #pragma mark Responding to Scrolling and Dragging
  227. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  228. {
  229. if ([self.delegate respondsToSelector:@selector(scrollViewDidScroll:)]) {
  230. [self.delegate scrollViewDidScroll:scrollView];
  231. }
  232. }
  233. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  234. {
  235. if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
  236. [self.delegate scrollViewWillBeginDragging:scrollView];
  237. }
  238. }
  239. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
  240. {
  241. if ([self.delegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) {
  242. [self.delegate scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset];
  243. }
  244. }
  245. - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
  246. {
  247. if ([self.delegate respondsToSelector:@selector(scrollViewShouldScrollToTop:)]) {
  248. return [self.delegate scrollViewShouldScrollToTop:scrollView];
  249. }
  250. return YES;
  251. }
  252. - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
  253. {
  254. if ([self.delegate respondsToSelector:@selector(scrollViewDidScroll:)]) {
  255. [self.delegate scrollViewDidScroll:scrollView];
  256. }
  257. }
  258. - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
  259. {
  260. if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginDecelerating:)]) {
  261. [self.delegate scrollViewWillBeginDecelerating:scrollView];
  262. }
  263. }
  264. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  265. {
  266. if ([self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
  267. [self.delegate scrollViewDidEndDecelerating:scrollView];
  268. }
  269. }
  270. //Managing Zooming
  271. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
  272. {
  273. if ([self.delegate respondsToSelector:@selector(viewForZoomingInScrollView:)]) {
  274. return [self.delegate viewForZoomingInScrollView:scrollView];
  275. }
  276. return nil;
  277. }
  278. - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
  279. {
  280. if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginZooming:withView:)]) {
  281. [self.delegate scrollViewWillBeginZooming:scrollView withView:view];
  282. }
  283. }
  284. - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
  285. {
  286. if ([self.delegate respondsToSelector:@selector(scrollViewDidEndZooming:withView:atScale:)]) {
  287. [self.delegate scrollViewDidEndZooming:scrollView withView:view atScale:scale];
  288. }
  289. }
  290. - (void)scrollViewDidZoom:(UIScrollView *)scrollView
  291. {
  292. if ([self.delegate respondsToSelector:@selector(scrollViewDidZoom:)]) {
  293. [self.delegate scrollViewDidZoom:scrollView];
  294. }
  295. }
  296. //Responding and Scrolling Animations
  297. - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
  298. {
  299. if ([self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)]) {
  300. [self.delegate scrollViewDidEndScrollingAnimation:scrollView];
  301. }
  302. }
  303. #pragma clang diagnostic pop
  304. @end