BBAPageViewController.h 6.49 KB
//
//  BBAFeedContainerViewController.h
//  BBAComs
//
//  Created by liyongrui on 2016/11/22.
//
//


#import "BBAPageViewControllerCellProtocal.h"
#import "BBAMultiTabBar.h"
#import "BBAUIViewController.h"

@class BBAPageViewController;

typedef NS_ENUM(NSUInteger, TransitionType) {
    TransitionTypeNone, //没切页面
    TransitionTypeDrag, //左右拖拽切页面
    TransitionTypeCall, //外部通过调用scrollToPage方法切页面
};
/**
 BBAPageViewControllerDelegate
 */
@protocol BBAPageViewControllerDelegate <NSObject>

@optional

///横向滑动,progress = offsetX / contentWidth
- (void)pageViewControllerSlidingProgressDidChange:(CGFloat)progress;

- (NSUInteger)defaultSelectedIndexForPageViewController:(nonnull BBAPageViewController *)pageViewController;

- (void)pageViewController:(nonnull BBAPageViewController *)pageViewController didSelectTabItemAtIndex:(NSInteger)index selectType:(BBAMultiTabBarSelectType)type;

- (void)pageViewController:(nonnull BBAPageViewController *)pageViewController didSelectTabItemAtIndex:(NSInteger)index isChanged:(BOOL)isChanged selectType:(BBAMultiTabBarSelectType)type;

///显示的cell发生了改变,changeType 参数暂为透传的 multiTabBar 的 selectType,待优化!
- (void)pageViewController:(nonnull BBAPageViewController *)pageViewController presentingPageCellDidChanged:(nullable UICollectionViewCell *)appearCell disappearCell:(nullable UICollectionViewCell *)disappearCell changeType:(BBAMultiTabBarSelectType)type;

//ScrollDelegate
- (void)pageViewControllerScrollViewWillBeginDragging:(nonnull UIScrollView *)scrollView;
- (void)pageViewControllerScrollViewDidEndDragging:(nonnull UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)pageViewControllerScrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView;

- (void)pageViewController:(nonnull BBAPageViewController *)pageViewController willChangeCellToIndex:(NSInteger)index transitionType:(TransitionType)type;

- (void)pageViewController:(nonnull BBAPageViewController *)pageViewController willDisplayCell:(UICollectionViewCell *)cell;
@end

/**
 BBAPageViewControllerDataSource
 */
@protocol BBAPageViewControllerDataSource <NSObject>

@required
- (NSInteger)numberOfPagesInPageViewController:(nonnull BBAPageViewController *)pageViewController;

- (nonnull __kindof UICollectionViewCell<BBAPageViewControllerCellProtocal> *)pageViewController:(nonnull BBAPageViewController *)pageViewController cellForPageAtIndexPath:(nonnull NSIndexPath *)indexPath;

@end

/**
 BBAPageViewController
 */
__attribute__ ((deprecated("该类已被废弃,请勿再使用")))
@interface BBAPageViewController : BBAUIViewController <BBAMultiTabBarDelegate>

///顶部Tab Bar
@property (nonatomic, strong, readonly, nonnull) BBAMultiTabBar *multiTabBar;

@property (nonatomic, weak, nullable) id<BBAPageViewControllerDelegate> delegate;
@property (nonatomic, weak, nullable) id<BBAPageViewControllerDataSource> dataSource;

///是否隐藏TabBar
@property (nonatomic, assign, getter= isMultiTabBarHidden) BOOL multiTabBarHidden;

///选中的 pageIndex,只有页面切换结束后才会更新
@property (nonatomic, readonly) NSUInteger selectedPageIndex; //当前page的index,只要不松手,就不会更新
///当前正展示的 pageIndex,实时计算更新
@property (nonatomic, readonly) NSUInteger presentingPageIndex; //当前最近page的Index,基于contentOffset计算
@property (nonatomic, readonly) NSUInteger pageCount;

///当前正展示的cell,实时计算更新
@property (nonatomic, weak, readonly, nullable) __kindof UICollectionViewCell *presentingPageCell;

///选中的cell,只有页面切换结束后才会更新
@property (nonatomic, readonly, nullable, weak) __kindof UICollectionViewCell *selectedPageCell;

///当前可见的indexPaths,只要露出,就算可见
@property (nonatomic, weak, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForVisiblePages;

//当前切页面的类型 (没切 | 点击tab切 | 滑动切)
@property (nonatomic, assign) TransitionType transitionState;

@property (nonatomic, assign, getter=isScrollLockEnabled) BOOL scrollLockEnabled; //横向滑动开关,供首页使用

@property (nonatomic, getter=isTranstionDraging, readonly) BOOL transtionDraging; //是否在横滑拖动切换中
@property (nonatomic, getter=isScrollDragDeceleratingFinished, readonly) BOOL scrollDragDeceleratingFinished; //是否在横滑拖动

///内容区域(不包含MultiTabBar)与RootView之间的EdgeInsects;默认值为 (TabBar高度, 0, 0, 0)
@property (nonatomic, assign) UIEdgeInsets contentAreaEdgeInsects;

//warning ZQT
@property (nonatomic, copy, nullable) void(^feedTabChangeDidFinishCompleteBlock)(BOOL success);

/// 是否启用自动生命周期管理
/// 默认值为NO,不建议更改
/// 设置为YES时,在add subVC的view时,会触发subVC的Appear事件;PageVC Appear/Disappear时,其所有页面子VC也都会被传递;
@property (nonatomic, assign) BOOL automaticallyForwardAppearanceMethods;

- (void)registerClass:(nonnull Class)cellClass forPageCellWithReuseIdentifier:(nonnull NSString *)identifier;
- (nonnull __kindof UICollectionViewCell *)dequeueReusablePageCellWithReuseIdentifier:(nonnull NSString *)identifier forIndexPath:(nonnull NSIndexPath *)indexPath;
- (nullable __kindof UICollectionViewCell *)cellForPageAtIndexPath:(nullable NSIndexPath *)indexPath;

- (void)reloadAllPages;
- (void)reloadAllPages:(BOOL)layoutImmediately; //是否需要立即生效
- (void)scrollToPageAtIndex:(NSUInteger)pageIndex animated:(BOOL)animated;
- (void)scrollToPageAtIndex:(NSUInteger)pageIndex animated:(BOOL)animated completion:(void (^_Nullable)(BOOL finished, NSUInteger currentPageIndex))completion;

/**
 设置内容区域的EdgeInsects
 
 @param contentAreaEdgeInsects 内容区域(不含MultiTabBar)的EdgeInsects
 @param layoutImmediately 是否立即刷新布局;只有EdgeInsects不同时,才会立即刷新布局
 */
- (void)setContentAreaEdgeInsects:(UIEdgeInsets)contentAreaEdgeInsects layoutImmediately:(BOOL)layoutImmediately;

/**
 * @brief 获取页面的 contentScrollView
 */
- (nullable UIScrollView *)contentScrollView;

/**
 添加 ChildViewController
 
 @param childViewController childViewController
 @param needsForwardAppearanceMethods 是否需要转发Appear相关生命周期事件;如不需要自动传递(例如每个Page的VC,不想要各个PgaeVC都Appear|Disappear),则传参数为NO
 */
- (void)addChildViewController:(nonnull UIViewController *)childViewController needsForwardAppearanceMethods:(BOOL)needsForwardAppearanceMethods;

@end