JPNavigationController 2.1.3

JPNavigationController 2.1.3

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2017年11月

NewPan 维护。



  • 作者:
  • NewPan

license pod pod pod
pod

这个库为 UIViewController 提供全屏 pop 和 push 手势,并支持为每个单例控制器的 UINavigationBar 进行自定义。在执行 pop 动作时支持使用 AVPlayer 播放视频。

功能

  • 全屏 pop 手势支持
  • 全屏 push 手势支持
  • 支持为每个单例控制器自定义 UINavigationBar
  • 支持在屏幕底部添加链接视图
  • 支持自定义屏幕左侧的 pop 和 push 手势距离
  • 支持为单个控制器关闭 pop 手势
  • 支持为所有控制器关闭 pop 手势
  • 在执行 pop 手势时支持使用 AVPlayer 播放视频

要求

  • iOS 8.0 或更高版本
  • Xcode 8.0 或更高版本

入门

交流

  • 如果你 发现了错误,开放一个问题。
  • 如果你 有功能请求,开放一个问题。
  • 如果你 想要贡献,提交一个 pull request。

安装

如何使用

初始化

Objective-C:

#import <JPNavigationControllerKit.h>

JPNavigationController *nav = [[JPNavigationController alloc]initWithRootViewController:YourVc];

PushViewController

Objective-C:

[self.navigationController pushViewController:YourVc animated:YES];

PopToViewController

Objective-C:

[self.navigationController popViewControllerAnimated:YES];

[self.navigationController popToRootViewControllerAnimated:YES];


// Pop to a given view controller.

// Plan A: find the target view controller by youself, then pop it.
JPNavigationControllerDemo_linkBar *vc = nil;
NSArray *viewControllers = self.navigationController.jp_rootNavigationController.jp_viewControllers;
for (UIViewController *c in viewControllers) {
    if ([c isKindOfClass:[JPNavigationControllerDemo_linkBar class]]) {
        vc = (JPNavigationControllerDemo_linkBar *)c;
        break;
    }
}

if (vc) {
    [self.navigationController popToViewController:vc animated:YES];
}


// Plan B: use jp_popToViewControllerClassString:handle:animated:.
[self.navigationController jp_popToViewControllerClassString:@"JPNavigationControllerDemo_linkBar" handle:^UIViewController * _Nullable(NSArray<UIViewController *> * _Nullable viewControllers, NSError * _Nullable error) {

    if (!error) {
        return viewControllers.firstObject;
    }
    else{
        NSLog(@"%@", error);
        return nil;
    }

} animated:YES];

自定义 UINavigationBar

Objective-C:

// Hide navigation bar.
self.navigationController.navigationBarHidden = YES;

// Customize UINavigationBar color
[self.navigationController.navigationBar setBackgroundImage:aImage forBarMetrics:UIBarMetricsDefault];

添加 push 手势连接 viewController

Objective-C:

// Become the delegate of JPNavigationControllerDelegate protocol and, implemented protocol method, then you own left-slip to push function.
[self.navigationController jp_registerNavigtionControllerDelegate:self];

// Implementation protocol method
- (void)navigationControllerDidPush:(JPNavigationController *)navigationController{
    [self.navigationController pushViewController:YourVc animated:YES];
}

添加添加屏幕底部的链接视图

Objective-C:

// Return the link view in the be pushed viewController.
- (void)viewDidLoad{
    [super viewDidLoad];

    YourVc.navigationController.jp_linkViewHeight = 44.0f;
    self.navigationController.jp_linkView = YourLinkView;
}

自定义 pop 手势距离

Objective-C:

self.navigationController.jp_interactivePopMaxAllowedInitialDistanceToLeftEdge = aValue;

为单个控制器关闭 pop 手势

Objective-C:

self.navigationController.jp_closePopForAllViewController = YES;

为所有控制器关闭 pop 手势

Objective-C:

self.navigationController.jp_closePopForAllViewController = YES;

使用自定义 pop 动画(当包含 AVPlayer 时使用)

Objective-C:

self.navigationController.jp_useCustomPopAnimationForCurrentViewController = YES;

安装

在你的项目中使用 JPNavigationController 有两种方法:

  • 使用 CocoaPods
  • 通过将项目克隆到你的仓库中

CocoaPods 安装

CocoaPods 是 Objective-C 的依赖管理器,它自动化并简化了在项目中使用第三方库的过程。查看 入门 部分,了解更多细节。

Podfile

platform :ios, '8.0'
target "YourProjectName" do
pod 'JPNavigationController', '~> 2.1.2'
end

许可

所有源代码都是在 MIT 许可证 之下。

如果你在中国

本框架支持为 UINavigationController 提供全屏 pop 和 push 手势,并且可以为每个控制器自定义 UINavigationBar。注意,每个控制器的 UINavigationBar 是互不干扰的。实现基于 AOP 思想,不会侵入你的项目。

特性

  • 全屏 pop 手势支持
  • 全屏 push 到绑定控制器支持
  • 支持为每个控制器定制 UINavigationBar(包括设置颜色和透明度)
  • 支持为每个控制器添加底部联动视图
  • 支持自定义 pop 手势范围(从屏幕最左侧开始计算宽度)
  • 支持为单个控制器关闭 pop 手势
  • 为所有控制器关闭 pop 手势支持
  • 当当前控制器使用 AVPlayer 播放视频时,使用自定义的 pop 动画以保证 AVPlayer 流畅播放。

组件要求

  • iOS 8.0 或更高版本
  • Xcode 8.0 或更高版本

了解实现思路和源码解析

联系

  • 如果你发现了bug,请帮我提交issue
  • 如果你有好的建议,请帮我提交issue
  • 如果你想贡献代码,请提交请求

安装

具体使用

初始化

Objective-C:

#import <JPNavigationControllerKit.h>

JPNavigationController *nav = [[JPNavigationController alloc]initWithRootViewController:YourVc];

PushViewController

Objective-C:

[self.navigationController pushViewController:YourVc animated:YES];

PopToViewController

Objective-C:

[self.navigationController popViewControllerAnimated:YES];

[self.navigationController popToRootViewControllerAnimated:YES];


// 弹出到指定的控制器

// 方案A: 找到目标控制器, pop
JPNavigationControllerDemo_linkBar *vc = nil;
NSArray *viewControllers = self.navigationController.jp_rootNavigationController.jp_viewControllers;
for (UIViewController *c in viewControllers) {
if ([c isKindOfClass:[JPNavigationControllerDemo_linkBar class]]) {
    vc = (JPNavigationControllerDemo_linkBar *)c;
    break;
   }
}

if (vc) {
    [self.navigationController popToViewController:vc animated:YES];
}


// 方案 B: jp_popToViewControllerClassString:handle:animated:.
[self.navigationController jp_popToViewControllerClassString:@"JPNavigationControllerDemo_linkBar" handle:^UIViewController * _Nullable(NSArray<UIViewController *> * _Nullable viewControllers, NSError * _Nullable error) {

    if (!error) {
        return viewControllers.firstObject;
    }
    else{
        NSLog(@"%@", error);
        return nil;
    }

} animated:YES];

自定义 UINavigationBar

Objective-C:

// 隐藏导航条.
self.navigationController.navigationBarHidden = YES;

// 自定义 UINavigationBar 颜色
[self.navigationController.navigationBar setBackgroundImage:aImage forBarMetrics:UIBarMetricsDefault];

添加push手势绑定控制器

Objective-C:

// 成为JPNavigationControllerDelegate协议的代理, 实现协议方法即可拥有左滑push功能.
[self.navigationController jp_registerNavigtionControllerDelegate:self];

// 实现协议方法
- (void)jp_navigationControllerDidPushLeft{
    [self.navigationController pushViewController:YourVc animated:YES];
}

添加底部联动视图支持

Objective-C:

// 你只需要在 viewDidLoad: 方法里把你的联动视图传给框架, 框架会制动帮你显示.
-(void)viewDidLoad{
    [super viewDidLoad];
    YourVc.navigationController.jp_linkViewHeight = 44.0f;
    self.navigationController.jp_linkView = YourLinkView;
}

自定义 pop 手势响应范围

Objective-C:

self.navigationController.jp_interactivePopMaxAllowedInitialDistanceToLeftEdge = aValue;

禁用单个控制器 pop 手势

Objective-C:

self.navigationController.jp_closePopForAllViewController = YES;

禁用所有控制器 pop 手势

Objective-C:

self.navigationController.jp_closePopForAllViewController = YES;

因为界面中有 AVPLayer 在播放视频,为了保证 pop 手势执行的过程中视频能正常播放,使用自定义的 pop 动画。

Objective-C:

self.navigationController.jp_useCustomPopAnimationForCurrentViewController = YES;

集成到你的项目

两种选择把框架集成到你的项目

  • 使用 CocoaPods
  • 下载我的demo,把'JPNavigationController'文件夹拽到你的项目中

使用 CocoaPods 安装

CocoaPods 是 Objective-C 的依赖管理器,它自动化并简化了在项目中使用第三方库的过程。查看 入门 部分,了解更多细节。

Podfile

platform :ios, '8.0'
target "YourProjectName" do
pod 'JPNavigationController', '~> 2.1.2'
end

证书

所有源代码都是在 MIT 许可证 之下。