All Projects → DarielChen → Dcurlrouter

DarielChen / Dcurlrouter

Licence: mit
通过自定义URL实现控制器之间的跳转

Labels

Projects that are alternatives of or similar to Dcurlrouter

Lotusoot
灵活的 Swift 组件解耦和通信工具
Stars: ✭ 324 (-17.56%)
Mutual labels:  router
Route Composer
Protocol oriented, Cocoa UI abstractions based library that helps to handle view controllers composition, navigation and deep linking tasks in the iOS application. Can be used as the universal replacement for the Coordinator pattern.
Stars: ✭ 362 (-7.89%)
Mutual labels:  router
Padavan
padavan 简体中文 & 路由器适配
Stars: ✭ 385 (-2.04%)
Mutual labels:  router
Ftpopovermenu swift
FTPopOverMenu_Swift, swift version of FTPopOverMenu. FTPopOverMenu is a pop over menu for iOS which is maybe the easiest one to use. Supports both portrait and landscape. It can show from any UIView, any UIBarButtonItem and any CGRect.
Stars: ✭ 326 (-17.05%)
Mutual labels:  pop
Ipt Netflow
Netflow iptables module for Linux kernel (official)
Stars: ✭ 357 (-9.16%)
Mutual labels:  router
Openwrtinvasion
Root shell exploit for several Xiaomi routers: 4A Gigabit, 4A 100M, 4, 4C, 3Gv2, 4Q, miWifi 3C...
Stars: ✭ 366 (-6.87%)
Mutual labels:  router
Graphpath
Graphpath generates an ASCII network diagram from the route table of a Unix/Linux
Stars: ✭ 321 (-18.32%)
Mutual labels:  router
Regexparam
A tiny (308B) utility that converts route patterns into RegExp. Limited alternative to `path-to-regexp` 🙇‍♂️
Stars: ✭ 390 (-0.76%)
Mutual labels:  router
Blog.vue
☘ 一个vue的个人博客项目,配合.net core api教程,打造前后端分离
Stars: ✭ 362 (-7.89%)
Mutual labels:  router
Krakend
Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
Stars: ✭ 4,752 (+1109.16%)
Mutual labels:  router
Kompass
Kotlin Multiplatform Router for Android and iOS
Stars: ✭ 328 (-16.54%)
Mutual labels:  router
Router
Simple middleware-style router
Stars: ✭ 350 (-10.94%)
Mutual labels:  router
Miox
Modern infrastructure of complex SPA
Stars: ✭ 374 (-4.83%)
Mutual labels:  router
Vue Router
🚦 The official router for Vue.js.
Stars: ✭ 18,606 (+4634.35%)
Mutual labels:  router
Uwebsockets.js
μWebSockets for Node.js back-ends 🤘
Stars: ✭ 4,552 (+1058.27%)
Mutual labels:  router
Router Module
Nuxt.js module to use router.js instead of pages/ directory.
Stars: ✭ 322 (-18.07%)
Mutual labels:  router
Asuswrt Merlin Transparent Proxy
transparent proxy base on ss, v2ray, ipset, iptables, chinadns on asuswrt merlin.
Stars: ✭ 367 (-6.62%)
Mutual labels:  router
Sower
Sower is a cross-platform intelligent transparent proxy solution.
Stars: ✭ 391 (-0.51%)
Mutual labels:  router
React
🔼 UI-Router for React
Stars: ✭ 386 (-1.78%)
Mutual labels:  router
Lazytransitions
Lazy pop and dismiss like in the Facebook, Instagram or Twitter apps.
Stars: ✭ 377 (-4.07%)
Mutual labels:  pop

DCURLRouter

介绍

通过自定义URL实现控制器之间的跳转.

主要功能:

  • 支持URL后面拼接参数;
  • 支持参数作为字典传入;
  • 支持在push的时候进行导航控制器的替换;
  • 支持在modal的时候添加导航控制器;
  • 支持一次pop和dismiss多个控制器;
  • 支持使用Xib加载控制器;
  • 自带block回调;
  • 兼容swift.

使用方法:

1. 把DCURLRouter这个文件夹拖到项目中.

2. 使用cocoapods:

pod 'DCURLRouter', '~> 0.81'

注意: 需要自己在项目中新建一个DCURLRouter.plist文件.


1.配置

  1. 创建DCURLRouter.一个plist文件,文件夹中有,只要修改下就行了,大概的对应关系如下图所示
  2. 加载DCURLRouter.plist文件数据
   [DCURLRouter loadConfigDictFromPlist:@"DCURLRouter.plist"];

2. push和modal的使用

所有的push和modal方法都可以通过DCURLRouter这个类方法来调用.这样在push和modal的时候就不需要拿到导航控制器或控制器再跳转了.也就是说,以后push和modal控制器跳转就不一定要在控制器中进行了.

1.push控制器

    // 不需要拼接参数直接跳转
    [DCURLRouter pushURLString:@"dariel://twoitem" animated:YES];
    
    // 直接把参数拼接在自定义url末尾
    NSString *urlStr = @"dariel://twoitem?name=dariel&userid=213213";
    [DCURLRouter pushURLString:urlStr animated:YES];
    // 可以将参数放入一个字典
    NSDictionary *dict = @{@"userName":@"Hello", @"userid":@"32342"};
    [DCURLRouter pushURLString:@"dariel://twoitem" query:dict animated:YES];

    // 如果当前控制器和要push的控制器是同一个,可以将replace设置为Yes,进行替换.
    [DCURLRouter pushURLString:@"dariel://oneitem" query:dict animated:YES replace:YES];
    
    // 重写了系统的push方法,直接通过控制器跳转
    TwoViewController *two = [[TwoViewController alloc] init];
    [DCURLRouter pushViewController:two animated:YES];

2.modal控制器 用法和push差不多,只是这里添加了一个给modal出来的控制器加一个导航控制器的方法.

   // 不需要拼接参数直接跳转
   [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES completion:nil];
   
   // 直接把参数拼接在自定义url末尾
   NSString *urlStr = @"dariel://threeitem?name=dariel&userid=213213";
   [DCURLRouter presentURLString:urlStr animated:YES completion:nil];

   // 可以将参数放入一个字典
   NSDictionary *dict = @{@"userName":@"Hello", @"userid":@"32342"};
   [DCURLRouter presentURLString:@"dariel://threeitem" query:dict animated:YES completion:nil];

   // 给modal出来的控制器添加一个导航控制器
   [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES withNavigationClass:[UINavigationController class] completion:nil];

   // 重写了系统的modal方法
   ThreeViewController *three = [[ThreeViewController alloc] init];
   [DCURLRouter presentViewController:three animated:YES completion:nil];

3. 后退 pop 和 dismiss

在实际开发中,好几次的界面的跳转组成了一个业务流程,整个业务流程结束后通常会要求返回最开始的界面,这就要让控制器连续后退好几次,但苹果是没有提供方法的.DCURLRouter给出了具体的实现方案.

pop:

   /** pop掉一层控制器 */
   + (void)popViewControllerAnimated:(BOOL)animated;
   /** pop掉两层控制器 */
   + (void)popTwiceViewControllerAnimated:(BOOL)animated;
   /** pop掉times层控制器 */
   + (void)popViewControllerWithTimes:(NSUInteger)times animated:(BOOL)animated;
   /** pop到根层控制器 */
   + (void)popToRootViewControllerAnimated:(BOOL)animated;

dismiss:

    /** dismiss掉1层控制器 */
    + (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion;
    /** dismiss掉2层控制器 */
    + (void)dismissTwiceViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion;
    /** dismiss掉times层控制器 */
    + (void)dismissViewControllerWithTimes:(NSUInteger)times animated: (BOOL)flag completion: (void (^ __nullable)(void))completion;
    /** dismiss到根层控制器 */
    + (void)dismissToRootViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion;

4.参数的接收,以及其它方法

在3中如果在自定义了URL后面拼接了参数,或者用字典传递了参数,那么在目的控制器怎么接收呢?其实参数的接收很简单.只要导入这个分类#import "UIViewController+DCURLRouter.h"就行了,然后就能拿到这三个参数.

    NSLog(@"接收的参数%@", self.params);
    NSLog(@"拿到URL:%@", self.originUrl);
    NSLog(@"URL路径:%@", self.path);

但有时我们我需要把值传递给发送push或者modal方的控制器,也就是逆传,也很简单,可以用代理.有方法可以拿到当前的控制器,以及导航控制器

或者用控制器分类自带的valueBlock属性回调

    // 拿到当前控制器
    UIViewController *currentController = [DCURLRouter sharedDCURLRouter].currentViewController;
    // 拿到当前控制器的导航控制器
    UINavigationController *currentNavgationController = [DCURLRouter sharedDCURLRouter].currentNavigationViewController;

5.具体的实现原理

简书

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].