CGXVerticalMenuListContainerView.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // CGXVerticalMenuListContainerView.h
  3. // CGXVerticalMenuView-OC
  4. //
  5. // Created by CGX on 2018/05/01.
  6. // Copyright © 2019 CGX. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "CGXVerticalMenuListContainerViewDelegate.h"
  10. @class CGXVerticalMenuListContainerView;
  11. /**
  12. 列表容器视图的类型
  13. - CollectionView: 使用UICollectionView。
  14. 优势:因为列表被添加到cell上,视图的内存占用更少。
  15. 劣势:因为cell重用机制的问题,导致列表下拉刷新视图,会因为被removeFromSuperview而被隐藏。需要参考做特殊处理。
  16. */
  17. @protocol CGXVerticalMenuListContainerViewDataSource <NSObject>
  18. /**
  19. 返回list的数量
  20. @param listContainerView 列表的容器视图
  21. @return list的数量
  22. */
  23. - (NSInteger)numberOfListsInlistContainerView:(CGXVerticalMenuListContainerView *)listContainerView;
  24. /**
  25. 根据index返回一个对应列表实例,需要是遵从`CGXVerticalMenuListContainerViewDelegate`协议的对象。
  26. 你可以代理方法调用的时候初始化对应列表,达到懒加载的效果。这也是默认推荐的初始化列表方法。你也可以提前创建好列表,等该代理方法回调的时候再返回也可以,达到预加载的效果。
  27. 如果列表是用自定义UIView封装的,就让自定义UIView遵从`CGXVerticalMenuListContainerViewDelegate`协议,该方法返回自定义UIView即可。
  28. 如果列表是用自定义UIViewController封装的,就让自定义UIViewController遵从`CGXVerticalMenuListContainerViewDelegate`协议,该方法返回自定义UIViewController即可。
  29. @param listContainerView 列表的容器视图
  30. @param index 目标下标
  31. @return 遵从CGXVerticalMenuListContainerViewDelegate协议的list实例
  32. */
  33. - (id<CGXVerticalMenuListContainerViewDelegate>)listContainerView:(CGXVerticalMenuListContainerView *)listContainerView initListForIndex:(NSInteger)index;
  34. @optional
  35. /**
  36. 返回自定义UIScrollView或UICollectionView的Class
  37. 某些特殊情况需要自己处理UIScrollView内部逻辑。比如项目用了FDFullscreenPopGesture,需要处理手势相关代理。
  38. @param listContainerView CGXVerticalMenuListContainerView
  39. @return 自定义UIScrollView实例
  40. */
  41. - (Class)scrollViewClassInlistContainerView:(CGXVerticalMenuListContainerView *)listContainerView;
  42. /**
  43. 控制能否初始化对应index的列表。有些业务需求,需要在某些情况才允许初始化某些列表,通过通过该代理实现控制。
  44. */
  45. - (BOOL)listContainerView:(CGXVerticalMenuListContainerView *)listContainerView canInitListAtIndex:(NSInteger)index;
  46. - (void)listContainerViewDidScroll:(UIScrollView *)scrollView;
  47. @end
  48. @interface CGXVerticalMenuListContainerView : UIView
  49. @property (nonatomic, strong, readonly) UICollectionView *collectionView;
  50. @property (nonatomic, strong, readonly) NSDictionary <NSNumber *, id<CGXVerticalMenuListContainerViewDelegate>> *validListDict; //已经加载过的列表字典。key是index,value是对应的列表
  51. /**
  52. 滚动切换的时候,滚动距离超过一页的多少百分比,就触发列表的初始化。默认0.01(即列表显示了一点就触发加载)。范围0~1,开区间不包括0和1
  53. */
  54. @property (nonatomic, assign) CGFloat initListPercent;
  55. @property (nonatomic, assign) BOOL bounces; //默认NO
  56. @property (nonatomic, assign,readonly) NSInteger currentIndex;
  57. @property (nonatomic, assign) BOOL isHorizontal; //默认NO
  58. - (instancetype)init NS_UNAVAILABLE;
  59. - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
  60. - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
  61. - (instancetype)initWithDelegate:(id<CGXVerticalMenuListContainerViewDataSource>)delegate NS_DESIGNATED_INITIALIZER;
  62. - (void)didClickSelectedItemAtIndex:(NSInteger)index;
  63. - (void)scrollSelectedItemAtIndex:(NSInteger)index;
  64. - (void)reloadData;
  65. @end