BBANavigationController.h 5.72 KB
//
//  BBANavigationController.h
//  BBAPods
//
//  Created by guojin on 16/4/7.
//  Copyright © 2016年 Baidu. All rights reserved.
//
/******************************************************************************/
// 描述:BBANavigationController
// 目的:负责UINavigationController中子控制器切换过程中的手势(全屏及侧滑手势)禁用/开启|状态栏Style管理|
// 使用的业务:视频落地页
/******************************************************************************/
#import <UIKit/UIKit.h>
#import <BBAUIKit/BBAShouldAutorotateProtocol.h>
#import "FullscreenPopGestureRecognizer.h"
#import "BBAThreeDirectionPopGestureManager.h"

#pragma mark - Notification
#define BBANavWillShowViewControllerNotification   @"BBANavWillShowViewControllerNotification"
#define BBANavDidShowViewControllerNotification    @"BBANavDidShowViewControllerNotification"


@interface BBANavigationController : UINavigationController

//栈外元素对旋转的控制(栈内元素通过实现UIViewController的shouldAutorotate,supportedInterfaceOrientations来管理)
@property(nonnull, assign)id<BBAShouldAutorotateProtocol>   rotateDelegate;

//动画期间pop的视图
@property (nullable, nonatomic, weak) UIViewController * popingController;

//全屏手势响应默认值 默认开启
@property (nonatomic,assign) BOOL defaultFullGesterShouldRecognizer;

//是否跳过转场动画
@property (nonatomic,assign) BOOL needSkipTransitionAnimation;
    
/// 特定主题
@property (nonatomic, copy) NSString* _Nonnull specificThemeMode;

- (nullable instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass
                                 rootViewController:(nullable UIViewController*)rootViewController;

//图集多方向手势控制
//手势控制(图集多方向 + 全屏手势)
- (void)forbidCustomizedPopGesture:(BOOL)forbid;

//用于外部调起时,栈内元素退场,需要VC实现bbaDismissBlock属性。(因为页面dismiss前可能会有保存缓存等操作,因此需要页面自己处理dismiss逻辑)
- (void)dismissTriggeredByOpenURL;

// 全屏手势或边缘手势正在响应
- (BOOL)isInScreenPopGesture;

//用于外部控制gesture的优先级
- (nullable UIGestureRecognizer *)fullScreenPopGesture;
- (nullable UIGestureRecognizer *)screenEdgePopGesture;

/**
 在调用UINavigationController -setViewControllers:animated:方法后检查位于顶部的vc支持的屏幕方向,旋转到正确方向;
 
 @param viewControllers The view controllers to place in the stack. The front-to-back order of the controllers in this array represents the new bottom-to-top order of the controllers in the navigation stack. Thus, the last item added to the array becomes the top item of the navigation stack.
 @param animated If YES, animate the pushing or popping of the top view controller. If NO, replace the view controllers without any animations.
 */
- (void)bba_setViewControllers:(nullable NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated;

@end


@interface UIViewController (BBANavigationControllerItem)

//Push、Pop时根据要展示的UIViewController属性,决定是否禁用右滑返回手势
@property(nonatomic, assign)BOOL bbaPopGestureDisable;

@end


@interface UIViewController (BBADismissTriggeredByOpenURL)

typedef void(^BBADismissBlock)(void);
//处理外部调起时页面退场,需要有退场需求的VC实现
@property (nullable, nonatomic, copy)BBADismissBlock bbaDismissBlock;

//VC退场处理函数,如果是VC销毁必须处理的请放在dealloc中处理,会被导航控制主动调用
- (void)bba_processingBeforeDealloc;

@end


//定义UIViewController生命周期协议,背景:pushViewController:animated:NO时,原栈顶元素收不到对应生命周期方法
@protocol BBAViewControllerLifeCycle <NSObject>

- (void)bbaViewWillDisappearWithNoAnimation;

@end

@interface UINavigationController (BBAUINavigationControllerChildController)

- (nullable UIViewController*)controllerInStack:(nullable Class)controllerClass
										fromTop:(BOOL)fromTop;
- (NSInteger)controllerIndexInStack:(nullable Class)controllerClass
							fromTop:(BOOL)fromTop;

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

/**
 * @brief 手势和动画期间的 topvc
 *
 * @return topvc
 */
- (nullable UIViewController *)bbaTransitingTopViewController;
- (nullable NSArray<UIViewController *> *)bbaViewControllers;
//兼容BBANavigation setViewControllers附带转屏校验, 非BBANavigation只进行setViewControllers转发
- (void)bba_setViewControllers:(nullable NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated;
@end


@protocol BBACustomTransitioningProtocol <NSObject>

@optional
- (nullable id <UIViewControllerInteractiveTransitioning>)bba_navigationController:(nullable UINavigationController *)navigationController
                                       interactionControllerForAnimationController:(nullable id <UIViewControllerAnimatedTransitioning>) animationController;

- (nullable id <UIViewControllerAnimatedTransitioning>)bba_navigationController:(nullable UINavigationController *)navigationController
                                                animationControllerForOperation:(UINavigationControllerOperation)operation
                                                             fromViewController:(nullable UIViewController *)fromVC
                                                               toViewController:(nullable UIViewController *)toVC;

- (nullable id)bba_gestureAnimationWithFromView:(nullable UIView *)fromView
                                         toView:(nullable UIView *)toView
                                  containerView:(nullable UIView *)layoutContainerView;

@end