Coder Social home page Coder Social logo

dito010 / jpnavigationcontroller Goto Github PK

View Code? Open in Web Editor NEW
363.0 12.0 74.0 8.69 MB

This library provides an fullScreen pop and push gesture for UINavigationController with customize UINavigationBar for each single support.

Home Page: http://www.jianshu.com/p/88bc827f0692

License: MIT License

Objective-C 98.67% Ruby 1.33%

jpnavigationcontroller's Introduction

license pod pod pod pod

This library provides an fullScreen pop and push gesture for UINavigationController with customize UINavigationBar for each single support and, smooth playing video use AVPlayer when perform pop gesture support.

Features

  • FullScreen pop gesture support
  • FullScreen push gesture support
  • Customize UINavigationBar for each single viewController support
  • Add link view hovering in screen bottom support
  • Customize pop and push gesture distance on the left side of the screen support
  • Close pop gesture for single viewController support
  • Close pop gesture for all viewController support
  • Smooth playing video use AVPlayer when perform pop gesture support

Requirements

  • iOS 8.0 or later
  • Xcode 8.0 or later

Getting Started

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

How To Use

Initialize

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_popToViewControllerWithClass:[JPNavigationControllerDemo_linkBar class] handler:^UIViewController * _Nullable(NSArray<UIViewController *> * _Nullable viewControllers, NSError * _Nullable error) {
        
        if (!error) {
            return viewControllers.firstObject;
        }
        else{
            NSLog(@"%@", error);
            return nil;
        }
        
    } animated:YES];

Custom UINavigationBar

Objective-C:

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

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

Add push gesture connect 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];
}

Add link view hovering in screen bottom

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;
}

Customize pop gesture distance

Objective-C:

self.navigationController.jp_interactivePopMaxAllowedInitialDistanceToLeftEdge = aValue;

Close pop gesture for single viewController

Objective-C:

self.navigationController.jp_closePopForAllViewController = YES;

Close pop gesture for all viewController

Objective-C:

self.navigationController.jp_closePopForAllViewController = YES;

Use custom pop animation when contain AVPlayer

Objective-C:

self.navigationController.jp_useCustomPopAnimationForCurrentViewController = YES;

Installation

There are two ways to use JPNavigationController in your project:

  • using CocoaPods
  • by cloning the project into your repository

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the Get Started section for more details.

Podfile

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

Licenses

All source code is licensed under the MIT License.

如果你在天朝

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

特性

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

组件要求

  • iOS 8.0 or later
  • Xcode 8.0 or later

了解实现思路和源码解析

联系

  • 如果你发现了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_popToViewControllerWithClass:[JPNavigationControllerDemo_linkBar class] handler:^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 is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the Get Started section for more details.

Podfile

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

证书

All source code is licensed under the MIT License.

赞助

你这一赞助,我写的就更来劲了!

微信赞助扫码

支付宝赞助扫码

jpnavigationcontroller's People

Contributors

chris-pan avatar dito010 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jpnavigationcontroller's Issues

error

[!] Error installing JPNavigationController
[!] /usr/bin/git clone https://github.com/newyjp/JPNavigationController.git /var/folders/nm/4974_cj15s5gyjfg8wj077qm0000gn/T/d20181111-3230-1y3sd4j --template= --single-branch --depth 1 --branch 2.1.3
Cloning into '/var/folders/nm/4974_cj15s5gyjfg8wj077qm0000gn/T/d20181111-3230-1y3sd4j'...
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

两个问题

1.UIViewController分类中:运行时动态添加的控制器感觉应该是用assign修饰的
2.popTo固定的控制器时出现问题

左滑push下一个vc的手势失效情况求解

ViewController.m的viewDidLoad里
self.tableView.contentInset = UIEdgeInsetsMake(headerHeight, -40, 0, 40); 左边距大雨-40左滑push失效,不太清楚到底为什么会这样,难道contentInset影响手势响应?请教大神

会对Tabbar造成影响

使用该导航控制器的话,tabbar会显示异常,看不到文字和图片信息


Oops~ 将tabbarItem作为nav的属性就没问题了~ o(╯□╰)o 希望作者可以注释下 :)

左滑push 对avplayer有影响

复现:
demo播放视频的方法放到viewdidload中 注释掉停止视频播放的方法 在左滑push过程中 avplayer会有一个被移除的效果(无画面 只有播放器view的背景 )

问一个问题,关于UIPercentDrivenInteractiveTransition的

我在UINavigationController里设置UINavigationControllerDelegate=self
实现以下两个代理方法

  • (id)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
    -(id)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id)animationController
    {
    if (self.operation == UINavigationControllerOperationPush) {

      LSInteractiveTransition *a= [[LSInteractiveTransition alloc]init];
      a.vc=self;
      self.interactiveTransition=a;
    
      return self.interation ? self.interactiveTransition : nil;
    

    }
    else{
    LSInteractiveTransition *a= [[LSInteractiveTransition alloc]init];
    self.interactiveTransition=a;
    return self.interation ? a : nil;
    }
    }

当我带自定义动画push时正常,当交互式push动画时,就闪退了,这是什么原因啊

自己又继承了一层,有好多毛病

首先是导航栏的背景色不能在继承的navigation的initialize方法调用了 必须在Viewcontroller的viewDidLoad调用,基类重写的了push方法,拦截改变 返回按钮文字都不奏效了,而且还影响了我隐藏tabbar的操作,tabbar一直都在底部,难道非得每次调用push方法然后在hidebottom吗,不闲麻烦吗

viewDidLoad问题

iOS对于UITabBarController上的UIViewController是延迟调用viewDidLoad的,即用户点击之后才调用这个方法。使用JPNavigationController之后,打开APP时会立即触发所有的UIViewController的viewDidLoad方法,这样可能会导致一些意想不到的结果。tabBar上的三个控制器竟然不是懒加载进去的,一启动tabBar上的三个控制器直接都调用了viewDidLoad方法

跳转崩溃

appdelegate.m:
UITabBarControllertab = (UITabBarController)self.window.rootViewController;

UINavigationController*nvc = tab.selectedViewController;

UIViewController*vc = nvc.visibleViewController;

LessonModel *model = [self getModelDic:userInfo];
LessonDetailViewController *LDVC = [LessonDetailViewController new];
LDVC.hidesBottomBarWhenPushed = YES;
LDVC.model = model;
[(BaseNavGationController *)vc.navigationController pushViewController:LDVC animated:YES];

崩溃至JPNavigationController.m 147行

Present JPNavigationController得不到释放的问题

十分感谢楼主的导航控制器,在最近的性能检测发现JPNavigationController出现了一点内存泄露,问题在于JPNavigationInteractiveTransitiondelegate属性使用了strong修饰符

/*!
 * \~english
 * delegate
 *
 * \~chinese
 * 代理
 */
@property(nonatomic, strong)id<JPNavigationInteractiveTransitionDelegate> delegate;

修改成weak修饰符即可解决问题

/*!
 * \~english
 * delegate
 *
 * \~chinese
 * 代理
 */
@property(nonatomic, weak)id<JPNavigationInteractiveTransitionDelegate> delegate;

导航条的问题

大神好,我最近想用你写的全屏左滑控制器的轮子。但是用在我的项目里有一个让我很头疼的BUG,一直没找出原因。就是我的主控制器初始化显示的时候,导航条的标题,左右item按钮都是我设计的样子,但是进入下一个控制器然后pop回来的时候,导航条的显示就都没了,左边的按钮也变成了你写的默认返回按钮图标了。求大神解析~谢谢

左滑动push有几率失败

2017-10-10 15:42:41.101235+0800 AX_iOS[420:80233] TIC TCP Conn Failed [26:0x1c0363a80]: 1:61 Err(61)
2017-10-10 15:42:41.101999+0800 AX_iOS[420:80233] Task <8E93D254-C32F-4D31-A25E-FE8B0D583A77>.<20> HTTP load failed (error code: -1004 [1:61])
2017-10-10 15:42:41.102266+0800 AX_iOS[420:80123] Task <8E93D254-C32F-4D31-A25E-FE8B0D583A77>.<20> finished with error - code: -1004
2017-10-10 15:43:25.435298+0800 AX_iOS[420:80123] TIC TCP Conn Failed [30:0x1c4361680]: 1:61 Err(61)
2017-10-10 15:43:25.435559+0800 AX_iOS[420:80123] Task .<21> HTTP load failed (error code: -1004 [1:61])
2017-10-10 15:43:25.436139+0800 AX_iOS[420:79887] Task .<21> finished with error - code: -1004
2017-10-10 15:43:26.580851+0800 AX_iOS[420:79439] 网络已连接
2017-10-10 15:43:48.411644+0800 AX_iOS[420:79439] 网络已连接
2017-10-10 15:43:48.653232+0800 AX_iOS[420:80616] TIC TCP Conn Failed [33:0x1c017d940]: 1:61 Err(61)
2017-10-10 15:43:48.653561+0800 AX_iOS[420:80616] Task .<22> HTTP load failed (error code: -1004 [1:61])
2017-10-10 15:43:48.654013+0800 AX_iOS[420:80694] Task .<22> finished with error - code: -1004
2017-10-10 15:43:48.991658+0800 AX_iOS[420:80694] TIC TCP Conn Failed [34:0x1c0365940]: 1:61 Err(61)
2017-10-10 15:43:48.991916+0800 AX_iOS[420:80694] Task <32044289-7E46-4A41-904A-B89CDD689F59>.<23> HTTP load failed (error code: -1004 [1:61])
2017-10-10 15:43:48.992323+0800 AX_iOS[420:80123] Task <32044289-7E46-4A41-904A-B89CDD689F59>.<23> finished with error - code: -1004
2017-10-10 15:43:49.549326+0800 AX_iOS[420:79439] nested pop animation can result in a corrupted navigation bar
2017-10-10 15:43:49.550414+0800 AX_iOS[420:79439] Attempting to begin a transition on navigation bar (<UINavigationBar: 0x101e560f0; frame = (0 20; 320 44); hidden = YES; opaque = NO; autoresize = W; layer = <CALayer: 0x1c0038020>>) while a transition is in progress.
2017-10-10 15:43:50.965416+0800 AX_iOS[420:79439] nested pop animation can result in a corrupted navigation bar
2017-10-10 15:43:50.965800+0800 AX_iOS[420:79439] Attempting to begin a transition on navigation bar (<UINavigationBar: 0x101e560f0; frame = (0 20; 320 44); hidden = YES; opaque = NO; autoresize = W; layer = <CALayer: 0x1c0038020>>) while a transition is in progress.
2017-10-10 15:43:51.998094+0800 AX_iOS[420:79439] nested pop animation can result in a corrupted navigation bar
2017-10-10 15:43:51.998404+0800 AX_iOS[420:79439] Attempting to begin a transition on navigation bar (<UINavigationBar: 0x101e560f0; frame = (0 20; 320 44); hidden = YES; opaque = NO; autoresize = W; layer = <CALayer: 0x1c0038020>>) while a transition is in progress.
2017-10-10 15:43:54.941056+0800 AX_iOS[420:79439] nested pop animation can result in a corrupted navigation bar
2017-10-10 15:43:54.941386+0800 AX_iOS[420:79439] Attempting to begin a transition on navigation bar (<UINavigationBar: 0x101e560f0; frame = (0 20; 320 44); hidden = YES; opaque = NO; autoresize = W; layer = <CALayer: 0x1c0038020>>) while a transition is in progress.
2017-10-10 15:43:58.097888+0800 AX_iOS[420:79439] nested pop animation can result in a corrupted navigation bar
2017-10-10 15:43:58.098228+0800 AX_iOS[420:79439] Attempting to begin a transition on navigation bar (<UINavigationBar: 0x101e560f0; frame = (0 20; 320 44); hidden = YES; opaque = NO; autoresize = W; layer = <CALayer: 0x1c0038020>>) while a transition is in progress.

感谢作者的分享- 真的非常不错!

不是来提问题的 而是看了作者的思路和实现方法,真的很不错,之前一直想模仿今日头条的左滑返回效果,可是没能实现,刚看到作者的方案,虽然有所不同,但使用也更加方便,特此感谢!

奔溃啦

//返回的时候这里崩溃

-(CGFloat)jp_interactivePopMaxAllowedInitialDistanceToLeftEdge{
#if CGFLOAT_IS_DOUBLE
return [objc_getAssociatedObject(self, _cmd) doubleValue];
#else
//模拟器在这里崩溃
return [objc_getAssociatedObject(self, _cmd) floatValue];
#endif
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.