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. - (void)setScrollIndicatorInsets:(UIEdgeInsets)scrollIndicatorInsets
  152. {
  153. self.tableView.scrollIndicatorInsets = scrollIndicatorInsets;
  154. }
  155. - (UIEdgeInsets)scrollIndicatorInsets
  156. {
  157. return self.tableView.scrollIndicatorInsets;
  158. }
  159. - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
  160. {
  161. self.tableView.showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;
  162. }
  163. - (BOOL)showsHorizontalScrollIndicator
  164. {
  165. return self.tableView.showsHorizontalScrollIndicator;
  166. }
  167. - (void)setShowsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator
  168. {
  169. self.tableView.showsVerticalScrollIndicator = showsVerticalScrollIndicator;
  170. }
  171. - (BOOL)showsVerticalScrollIndicator
  172. {
  173. return self.tableView.showsVerticalScrollIndicator;
  174. }
  175. #pragma mark Zooming and Panning
  176. - (UIPanGestureRecognizer *)panGestureRecognizer
  177. {
  178. return self.panGestureRecognizer;
  179. }
  180. - (UIPinchGestureRecognizer *)pinchGestureRecognizer
  181. {
  182. return self.pinchGestureRecognizer;
  183. }
  184. - (void)setZoomScale:(CGFloat)zoomScale
  185. {
  186. self.tableView.zoomScale = zoomScale;
  187. }
  188. - (CGFloat)zoomScale
  189. {
  190. return self.tableView.zoomScale;
  191. }
  192. - (void)setMaximumZoomScale:(CGFloat)maximumZoomScale
  193. {
  194. self.tableView.maximumZoomScale = maximumZoomScale;
  195. }
  196. - (CGFloat)maximumZoomScale
  197. {
  198. return self.tableView.maximumZoomScale;
  199. }
  200. - (void)setMinimumZoomScale:(CGFloat)minimumZoomScale
  201. {
  202. self.tableView.minimumZoomScale = minimumZoomScale;
  203. }
  204. - (CGFloat)minimumZoomScale
  205. {
  206. return self.tableView.minimumZoomScale;
  207. }
  208. - (BOOL)zoomBouncing
  209. {
  210. return self.tableView.zoomBouncing;
  211. }
  212. - (BOOL)zooming
  213. {
  214. return self.tableView.zooming;
  215. }
  216. - (void)setBouncesZoom:(BOOL)bouncesZoom
  217. {
  218. self.tableView.bouncesZoom = bouncesZoom;
  219. }
  220. - (BOOL)bouncesZoom
  221. {
  222. return self.tableView.bouncesZoom;
  223. }
  224. #pragma mark Responding to Scrolling and Dragging
  225. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  226. {
  227. if ([self.delegate respondsToSelector:@selector(scrollViewDidScroll:)]) {
  228. [self.delegate scrollViewDidScroll:scrollView];
  229. }
  230. }
  231. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  232. {
  233. if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
  234. [self.delegate scrollViewWillBeginDragging:scrollView];
  235. }
  236. }
  237. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
  238. {
  239. if ([self.delegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) {
  240. [self.delegate scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset];
  241. }
  242. }
  243. - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
  244. {
  245. if ([self.delegate respondsToSelector:@selector(scrollViewShouldScrollToTop:)]) {
  246. return [self.delegate scrollViewShouldScrollToTop:scrollView];
  247. }
  248. return YES;
  249. }
  250. - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
  251. {
  252. if ([self.delegate respondsToSelector:@selector(scrollViewDidScroll:)]) {
  253. [self.delegate scrollViewDidScroll:scrollView];
  254. }
  255. }
  256. - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
  257. {
  258. if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginDecelerating:)]) {
  259. [self.delegate scrollViewWillBeginDecelerating:scrollView];
  260. }
  261. }
  262. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  263. {
  264. if ([self.delegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
  265. [self.delegate scrollViewDidEndDecelerating:scrollView];
  266. }
  267. }
  268. //Managing Zooming
  269. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
  270. {
  271. if ([self.delegate respondsToSelector:@selector(viewForZoomingInScrollView:)]) {
  272. return [self.delegate viewForZoomingInScrollView:scrollView];
  273. }
  274. return nil;
  275. }
  276. - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
  277. {
  278. if ([self.delegate respondsToSelector:@selector(scrollViewWillBeginZooming:withView:)]) {
  279. [self.delegate scrollViewWillBeginZooming:scrollView withView:view];
  280. }
  281. }
  282. - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
  283. {
  284. if ([self.delegate respondsToSelector:@selector(scrollViewDidEndZooming:withView:atScale:)]) {
  285. [self.delegate scrollViewDidEndZooming:scrollView withView:view atScale:scale];
  286. }
  287. }
  288. - (void)scrollViewDidZoom:(UIScrollView *)scrollView
  289. {
  290. if ([self.delegate respondsToSelector:@selector(scrollViewDidZoom:)]) {
  291. [self.delegate scrollViewDidZoom:scrollView];
  292. }
  293. }
  294. //Responding and Scrolling Animations
  295. - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
  296. {
  297. if ([self.delegate respondsToSelector:@selector(scrollViewDidEndScrollingAnimation:)]) {
  298. [self.delegate scrollViewDidEndScrollingAnimation:scrollView];
  299. }
  300. }
  301. #pragma clang diagnostic pop
  302. @end