BBAThreeDirectionPopGestureManager.h 4.11 KB
//
//  BBAPopGestureManager.h
//  BBAPods
//
//  Created by liuchengqing01 on 2017/7/19.
//  Copyright © 2017年 Baidu. All rights reserved.
//

#import <UIKit/UIKit.h>

/////////////////////////////////////////////////////////////////////////////////
// Added by zhangjian
/**
 * BBANavigationControllerDelegate代理方法传出去的参数
 * BBANavigationSwipeDirectionHorizontal 横向滑动
 * BBANavigationSwipeDirectionVertical 纵向滑动
 */
typedef enum : NSUInteger {
    BBANavigationSwipeDirectionHorizontal = 1,
    BBANavigationSwipeDirectionVertical = 2,
} BBANavigationSwipeDirection;

/**
 * controller支持的滑动样式 三种,不支持,上滑,下滑
 */
typedef enum : NSUInteger {
    BBANavigationDontSupportSwipeBack = 0,
    BBANavigationOnlySupportRightSwipeBack = 1,
    BBANavigationSupportThreeDirectionsSwipeBack = 2,
} BBANavigationSupportSwipeDirection;


@interface UIViewController (BBANavigationControllerSwipeBack)

/**
 * 是否应该跳过本地ViewAppear和ViewDidAppear调用
 * 改变量用于跳过viewcontroller中多出来的一次 ViewWillAppear和ViewDidAppear调用
 */
@property(nonatomic, assign) BOOL bba_shouldSkipViewAppear;

/**
 * viewcontroller是否需要在view will appear和view will disappear的时候刷新视图,如果需要怎需要实现下面的方法,保证滑动的时候视图是对的,同时也保证 view will appear等方法操作是合理的。
 注意:需要在自己的controller中viewWillAppear处,添加动画控制的变量,防止多次执行,viewWillAppear等.
 给controller设置两个变量,在viewWillAppear的时候:
 if(duringAppearAnimation){
 return;
 duringAppearAnimation = YES;
 }
 在viewWillDisappear的时候:
 if(duringDisappearAnimation){
 return;
 duringDisappearAnimation = YES;
 }
 最后在viewDidAppear和ViewDidDisappear的时候将 duringDisappearAnimation 和 duringAppearAnimation 置成yes
 
 */
// 废弃
//-(BOOL)bba_navigationControllerSupportViewChangeWhenAppearAndDisappear;

// 默认开启viewcontroller同步, 兼容旧逻辑, 提供delay接口

/**
 兼容旧逻辑, 提供delay接口
 默认开启viewcontroller生命周期同步, 即与系统调用appear/disappear的时机一致
 return YES: delay viewcontroller生命周期调用, 即手势期间不触发生命周期, 手势结束后实际开始pop操作时再触发生命周期
 */
-(BOOL)bba_navigationControllerDirectionPopShouldDelayAppearAndDisappear;

/**
 * 滑动的样式
 */
-(BBANavigationSupportSwipeDirection)bba_navigationControllerSupportSwipeDirection;

/**
 * 设置滑动渐变背景色
 */
-(nullable UIColor *)bba_navigationControllerMaskViewColor;

/**
 * 设置滑动渐变背景色横向滑动最大alpha
 */
-(nullable NSNumber *)bba_navigationControllerMaskViewHorizontalMaxAlpha;

/**
 * 设置滑动渐变背景色纵向滑动最大alpha
 */
-(nullable NSNumber *)bba_navigationControllerMaskViewVerticalMaxAlpha;

/**
 * 用户开始滑动退出
 */
- (void)bba_navigationWillPopViewController:(BBANavigationSwipeDirection)direction;

/**
 * 滑动退出即将成功执行
 */
- (void)bba_navigationWillFinishPopViewController:(BBANavigationSwipeDirection)direction;

/**
 * 滑动退出将要取消
 */
- (void)bba_navigationWillCancelPopViewController:(BBANavigationSwipeDirection)direction;

/**
 * 滑动退出已经取消
 */
- (void)bba_navigationDidCancelPopViewController:(BBANavigationSwipeDirection)direction;

/**
 * 完成popViewController
 */
- (void)bba_navigationDidFinishPopViewController;

@end
/////////////////////////////////////////////////////////////////////////////////


@interface BBAThreeDirectionPopGestureManager : NSObject

//兼容适配BBANavigationController
@property (nullable, nonatomic,strong) UIPanGestureRecognizer * recognizer;
//是否正在响应手势
@property (nonatomic, assign, readonly) BOOL isMoving;

- (nullable instancetype)initWithNavigationController:(nonnull UINavigationController *)navigation;

//用于手势期间获取栈内元素
- (nullable UIViewController *)bbaAnimationTopViewController;
- (nullable UIViewController *)bbaTopViewController;
- (nullable NSArray<__kindof UIViewController *> *)bbaViewControllers;

@end