VTContentView.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // VTContentView.h
  3. // VTMagicView
  4. //
  5. // Created by tianzhuo on 14/12/29.
  6. // Copyright (c) 2014年 tianzhuo. All rights reserved.
  7. // 内容页
  8. #import <UIKit/UIKit.h>
  9. #import "VTMagicMacros.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class VTContentView;
  12. /**
  13. * 数据源协议
  14. */
  15. @protocol VTContentViewDataSource <NSObject>
  16. /**
  17. * 根据索引获取对应的控制器
  18. *
  19. * @param contentView self
  20. * @param pageIndex 索引
  21. *
  22. * @return 当前索引对应的控制器
  23. */
  24. - (nullable UIViewController *)contentView:(VTContentView *)contentView viewControllerAtPage:(NSUInteger)pageIndex;
  25. @end
  26. @interface VTContentView : UIScrollView
  27. /**
  28. * 数据源
  29. */
  30. @property (nonatomic, weak, nullable) id <VTContentViewDataSource> dataSource;
  31. /**
  32. * 页面数量
  33. */
  34. @property (nonatomic, assign) NSUInteger pageCount;
  35. /**
  36. * 当前页面索引
  37. */
  38. @property (nonatomic, assign) NSUInteger currentPage;
  39. /**
  40. * 是否需要预加载下一页,默认YES
  41. */
  42. @property (nonatomic, assign) BOOL needPreloading;
  43. /**
  44. * 当前屏幕上已加载的控制器
  45. */
  46. @property (nonatomic, strong, readonly) NSArray *visibleList;
  47. #pragma mark - public methods
  48. /**
  49. * 刷新数据
  50. */
  51. - (void)reloadData;
  52. /**
  53. * 重置所有内容页的frame
  54. */
  55. - (void)resetPageFrames;
  56. /**
  57. * 清除所有缓存的页面
  58. */
  59. - (void)clearMemoryCache;
  60. /**
  61. * 根据控制器获取对应的页面索引,仅当前显示的和预加载的控制器有相应索引,
  62. * 若没有找到相应索引则返回NSNotFound
  63. *
  64. * @param viewController 页面控制器
  65. *
  66. * @return 页面索引
  67. */
  68. - (NSInteger)pageIndexForViewController:(nullable UIViewController *)viewController;
  69. /**
  70. * 根据页面索引获取对应页面的frame
  71. *
  72. * @param pageIndex 页面索引
  73. *
  74. * @return 页面索引
  75. */
  76. - (CGRect)frameOfViewControllerAtPage:(NSUInteger)pageIndex;
  77. /**
  78. * 获取索引对应的ViewController
  79. * 若index超出范围或对应控制器不可见,则返回nil
  80. *
  81. * @param pageIndex 索引
  82. *
  83. * @return UIViewController对象
  84. */
  85. - (nullable UIViewController *)viewControllerAtPage:(NSUInteger)pageIndex;
  86. /**
  87. * 根据索引生成对应的ViewController,若对应ViewController已经存在,则直接返回
  88. *
  89. * @param pageIndex 索引
  90. *
  91. * @return UIViewController对象
  92. */
  93. - (nullable UIViewController *)creatViewControllerAtPage:(NSUInteger)pageIndex;
  94. /**
  95. * 获取索引对应的ViewController,当ViewController为nil时,根据autoCreate的值决定是否创建
  96. *
  97. * @param pageIndex 索引
  98. * @param autoCreate 是否需要自动创建新的ViewController
  99. *
  100. * @return UIViewController对象
  101. */
  102. - (nullable UIViewController *)viewControllerAtPage:(NSUInteger)pageIndex autoCreate:(BOOL)autoCreate;
  103. /**
  104. * 根据缓存标识查询可重用的UIViewController
  105. *
  106. * @param identifier 缓存重用标识
  107. *
  108. * @return 可重用的视图控制器
  109. */
  110. - (nullable __kindof UIViewController *)dequeueReusablePageWithIdentifier:(NSString *)identifier;
  111. @end
  112. NS_ASSUME_NONNULL_END