FFRouter
中文教程
FFRouter 是一个功能强大且易于使用的 iOS URL 路由库,支持 URL 重写,允许 APP 在发布后动态修改相关路由逻辑。基于匹配查找 URL 比基于遍历查找更高效!集成和使用非常简单!
功能
- 具备基本的 URL 注册、路由、取消注册、打印日志等。
- 支持正逆向传值
- 支持使用通配符 (*) 注册 URL
- 支持 URL 重写
- 支持在重写时获取原始 URL 参数或 URLComponents,并可以进行 URL 编码或解码
- 支持通过 URL 获取对象
- 支持在路由 URL 时通过异步回调获取对象
- 支持在路由 URL 时传输非传统对象
- 支持路由未注册 URL 的统一回调
安装
CocoaPods
target 'MyApp' do
pod 'FFRouter'
end
运行 pod install
手动安装
将 FFRouter
文件夹添加到您的项目中
使用方法
首先
#import "FFRouter.h"
1、基本用法
/**
Register URL,use it with 'routeURL:' and 'routeURL: withParameters:'.
@param routeURL Registered URL
@param handlerBlock Callback after route
*/
+ (void)registerRouteURL:(NSString *)routeURL handler:(FFRouterHandler)handlerBlock;
/**
Register URL,use it with 'routeObjectURL:' and ‘routeObjectURL: withParameters:’,can return a Object.
@param routeURL Registered URL
@param handlerBlock Callback after route, and you can get a Object in this callback.
*/
+ (void)registerObjectRouteURL:(NSString *)routeURL handler:(FFObjectRouterHandler)handlerBlock;
/**
Registered URL, use it with `routeCallbackURL: targetCallback:'and `routeCallback URL: withParameters: targetCallback:', calls back `targetCallback' asynchronously to return an Object
@param routeURL Registered URL
@param handlerBlock Callback after route,There is a `targetCallback' in `handlerBlock', which corresponds to the `targetCallback:' in `routeCallbackURL: targetCallback:'and `routeCallbackURL: withParameters: targetCallback:', which can be used for asynchronous callback to return an Object.
*/
+ (void)registerCallbackRouteURL:(NSString *)routeURL handler:(FFCallbackRouterHandler)handlerBlock;
/**
Determine whether URL can be Route (whether it has been registered).
@param URL URL to be verified
@return Can it be routed
*/
+ (BOOL)canRouteURL:(NSString *)URL;
/**
Route a URL
@param URL URL to be routed
*/
+ (void)routeURL:(NSString *)URL;
/**
Route a URL and bring additional parameters.
@param URL URL to be routed
@param parameters Additional parameters
*/
+ (void)routeURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
/**
Route a URL and get the returned Object
@param URL URL to be routed
@return Returned Object
*/
+ (id)routeObjectURL:(NSString *)URL;
/**
Route a URL and bring additional parameters. get the returned Object
@param URL URL to be routed
@param parameters Additional parameters
@return Returned Object
*/
+ (id)routeObjectURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
/**
Route a URL, 'targetCallBack' can asynchronously callback to return a Object.
@param URL URL to be routed
@param targetCallback asynchronous callback
*/
+ (void)routeCallbackURL:(NSString *)URL targetCallback:(FFRouterCallback)targetCallback;
/**
Route a URL with additional parameters, and 'targetCallBack' can asynchronously callback to return a Object.
@param URL URL to be routed
@param parameters Additional parameters
@param targetCallback asynchronous callback
*/
+ (void)routeCallbackURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters targetCallback:(FFRouterCallback)targetCallback;
/**
Route callback for an unregistered URL
@param handler Callback
*/
+ (void)routeUnregisterURLHandler:(FFRouterUnregisterURLHandler)handler;
/**
Cancel registration of a URL
@param URL URL to be cancelled
*/
+ (void)unregisterRouteURL:(NSString *)URL;
/**
Unregister all URL
*/
+ (void)unregisterAllRoutes;
/**
Whether to display Log for debugging
@param enable YES or NO.The default is NO
*/
+ (void)setLogEnabled:(BOOL)enable;
【说明】
(1)注册 URL
三种类型的 URL:
[FFRouter registerRouteURL:@"protocol://page/routerDetails/:id" handler:^(NSDictionary *routerParameters) {
//Callbacks of Route's URL match with this registration URL
//routerParameters contains all the parameters that are passed
}];
[FFRouter registerRouteURL:@"wildcard://*" handler:^(NSDictionary *routerParameters) {
//Callbacks of Route's URL match with this registration URL
//routerParameters contains all the parameters that are passed
}];
[FFRouter registerRouteURL:@"protocol://page/routerObjectDetails" handler:^(NSDictionary *routerParameters) {
//Callbacks of Route's URL match with this registration URL
//routerParameters contains all the parameters that are passed
}];
可以通过 routerParameters
,routerParameters[FFRouterParameterURLKey]
获取 URL 中的参数,routerParameters[FFRouterParameterURLKey]
是完整的 URL。
注册和路由的三个方法:
//Way 1:
+ (void)registerRouteURL:(NSString *)routeURL handler:(FFRouterHandler)handlerBlock;
//Use the following two Route methods
+ (void)routeURL:(NSString *)URL;
+ (void)routeURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
//Way 2:
+ (void)registerObjectRouteURL:(NSString *)routeURL handler:(FFObjectRouterHandler)handlerBlock;
//Use the following two Route methods
+ (id)routeObjectURL:(NSString *)URL;
+ (id)routeObjectURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
//Way 3:
+ (void)registerCallbackRouteURL:(NSString *)routeURL handler:(FFCallbackRouterHandler)handlerBlock;
//Use the following two Route methods
+ (void)routeCallbackURL:(NSString *)URL targetCallback:(FFRouterCallback)targetCallback;
+ (void)routeCallbackURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters targetCallback:(FFRouterCallback)targetCallback;
(2)当需要使用以下方法时:
+ (id)routeObjectURL:(NSString *)URL;
路由 URL 并获取返回值,需要使用以下方法注册 URL:
+ (void)registerObjectRouteURL:(NSString *)routeURL handler:(FFObjectRouterHandler)handlerBlock;
并在 handlerBlock
中返回相应的对象,例如:
//Register and return the necessary values
[FFRouter registerObjectRouteURL:@"protocol://page/routerObjectDetails" handler:^id(NSDictionary *routerParameters) {
NSString *str = @“According to the need to return the necessary Object”;
return str;
}];
//Gets the returned value
NSString *ret = [FFRouter routeObjectURL:@"protocol://page/routerObjectDetails"];
(3)如果希望在路由 URL 后通过异步回调获取返回对象,可以使用以下方法注册和路由 URL
//Register URL and return to Object by callback at the necessary time.
[FFRouter registerCallbackRouteURL:@"protocol://page/RouterCallbackDetails" handler:^(NSDictionary *routerParameters, FFRouterCallback targetCallBack) {
//When necessary, return to Object through'targetCallBack'callback.
targetCallBack(@"Any Object");
}];
//When Route URL, by 'targetCallback' callbacks to get Object returned
[FFRouter routeCallbackURL:@"protocol://page/RouterCallbackDetails?nickname=imlifengfeng" targetCallback:^(id callbackObjc) {
self.testLabel.text = [NSString stringWithFormat:@"%@",callbackObjc];
}];
(4)如果您需要传输非常规对象作为参数,例如 UIImage
,可以使用以下方法:
[FFRouter routeURL:@"protocol://page/routerDetails?nickname=imlifengfeng" withParameters:@{@"img":[UIImage imageNamed:@"router_test_img"]}];
如果只需要传递常用参数,可以直接在 URL 后拼接参数:
[FFRouter routeURL:@"protocol://page/routerDetails?nickname=imlifengfeng&id=666¶meters......"];
然后从 routerParameters
中获取这些参数。例如:routerParameters[@"nickname"]
2、URL 重写
/**
According to the set of Rules, go to rewrite URL.
@param url URL to be rewritten
@return URL after being rewritten
*/
+ (NSString *)rewriteURL:(NSString *)url;
/**
Add a RewriteRule
@param matchRule Regular matching rule
@param targetRule Conversion rules
*/
+ (void)addRewriteMatchRule:(NSString *)matchRule targetRule:(NSString *)targetRule;
/**
Add multiple RewriteRule at the same time, the format must be:@[@{@"matchRule":@"YourMatchRule",@"targetRule":@"YourTargetRule"},...]
@param rules RewriteRules
*/
+ (void)addRewriteRules:(NSArray<NSDictionary *> *)rules;
/**
Remove a RewriteRule
@param matchRule MatchRule to be removed
*/
+ (void)removeRewriteMatchRule:(NSString *)matchRule;
/**
Remove all RewriteRule
*/
+ (void)removeAllRewriteRules;
【说明】
(1)您可以使用正则表达式
添加重写规则,例如:当URL为https://www.amazon.com/search/Atomic_bomb
时,拦截并使用本地注册的URL:protocol://page/routerDetails?product=Atomic_bomb
打开。首先添加重写规则:
[FFRouterRewrite addRewriteMatchRule:@"(?:https://)?www.amazon.com/search/(.*)" targetRule:@"protocol://page/routerDetails?product=$1"];
打开URL:https://www.amazon.com/search/Atomic_bomb
后,将重写为URL:protocol://page/routerDetails?product=Atomic_bomb
。
[FFRouter routeURL:@"https://www.amazon.com/search/Atomic_bomb"];
(2)您可以使用以下方法添加多个规则:
+ (void)addRewriteRules:(NSArray<NSDictionary *> *)rules;
规则格式必须以下列格式:
@[@{@"matchRule":@"YourMatchRule1",@"targetRule":@"YourTargetRule1"},
@{@"matchRule":@"YourMatchRule2",@"targetRule":@"YourTargetRule2"},
@{@"matchRule":@"YourMatchRule3",@"targetRule":@"YourTargetRule3"},]
(3)重写规则中的保留词:
- 通过
$scheme
、$host
、$port
、$path
、$query
、$fragment
获取标准URL的对应部分。通过$url
获取完整的URL。 - 使用
$1
、$2
、$3
... 通过括号获取matchRule
规则的参数。 $
:原始变量的值,$$
:原始变量的URL编码值,$#
:原始变量的URL解码值。
例如:对于Rewrite规则(?:https://)?www.taobao.com/search/(.*)
,用于https://www.taobao.com/search/原子弹
。
$1=原子弹
$$1=%e5%8e%9f%e5%ad%90%e5%bc%b9
同样,对于Rewrite规则(?:https://)?www.taobao.com/search/(.*)
,用于https://www.taobao.com/search/%e5%8e%9f%e5%ad%90%e5%bc%b9
。
$1=%e5%8e%9f%e5%ad%90%e5%bc%b9
$#1=原子弹
2、FFRouterNavigation
考虑到频繁使用路由配置UIViewController
之间的跳转,添加了一个额外的工具FFRouterNavigation
,以更容易地控制UIViewController
之间的跳转。使用方法如下
/**
Whether TabBar automatically hide when push
@param hide Whether to automatically hide, the default is NO
*/
+ (void)autoHidesBottomBarWhenPushed:(BOOL)hide;
/**
Get current ViewController
@return Current ViewController
*/
+ (UIViewController *)currentViewController;
/**
Get current NavigationViewController
@return return Current NavigationViewController
*/
+ (nullable UINavigationController *)currentNavigationViewController;
/**
Push ViewController
@param viewController Target ViewController
@param animated Whether to use animation
*/
+ (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
/**
Push ViewController,can set whether the current ViewController is still reserved.
@param viewController Target ViewController
@param replace whether the current ViewController is still reserved
@param animated Whether to use animation
*/
+ (void)pushViewController:(UIViewController *)viewController replace:(BOOL)replace animated:(BOOL)animated;
/**
Push multiple ViewController
@param viewControllers ViewController Array
@param animated Whether to use animation
*/
+ (void)pushViewControllerArray:(NSArray *)viewControllers animated:(BOOL)animated;
/**
present ViewController
@param viewController Target ViewController
@param animated Whether to use animation
@param completion Callback
*/
+ (void)presentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^ __nullable)(void))completion;
/**
Close the current ViewController, push, present universal
@param animated Whether to use animation
*/
+ (void)closeViewControllerAnimated:(BOOL)animated;
许可协议
中文使用说明
FFRouter 是 iOS 中一个强大且易用的 URL 路由库,支持 URL Rewrite,使 APP 在发布后也能动态修改相关路由逻辑。基于匹配查找 URL,效率高。集成和使用都非常简单!
功能
- 具有基本的 URL 注册、路由、注销注册、打印日志等功能
- 支持正向和反向传值
- 支持使用通配符(*)注册 URL
- 支持 URL 重写
- 支持在重写时获取原始 URL 参数或 URLComponents,并可对其进行 URL 编码或解码
- 支持通过 URL 获取对象
- 支持通过异步回调的方式获取对象,用于路由 URL
- 支持在路由 URL 时传递非常规对象
- 支持在路由未注册的 URL 时进行统一回调
安装
CocoaPods
target 'MyApp' do
pod 'FFRouter'
end
运行 pod install
手动安装
将 FFRouter
文件夹添加到你的项目中
使用方法
首先
#import "FFRouter.h"
1、基本使用
/**
注册 url,与 ‘routeURL:’ 和 ‘routeURL: withParameters:’ 配合使用
@param routeURL 要注册的 URL
@param handlerBlock URL 被 Route 后的回调
*/
+ (void)registerRouteURL:(NSString *)routeURL handler:(FFRouterHandler)handlerBlock;
/**
注册 URL,与 'routeObjectURL:' 和 ‘routeObjectURL: withParameters:’ 配合使用,可返回一个 Object
@param routeURL 要注册的 URL
@param handlerBlock URL 被 Route 后的回调,可在回调中返回一个 Object
*/
+ (void)registerObjectRouteURL:(NSString *)routeURL handler:(FFObjectRouterHandler)handlerBlock;
/**
注册 URL,与 ‘routeCallbackURL: targetCallBack:’ 和 ‘routeCallbackURL: withParameters: targetCallBack:’ 配合使用,可异步回调返回一个 Object
@param routeURL 要注册的 URL
@param handlerBlock URL 被 Route 后的回调,handlerBlock 中有一个 targetCallBack ,对应 ‘routeCallbackURL: targetCallBack:’ 和 ‘routeCallbackURL: withParameters: targetCallBack:’ 中的 targetCallBack,可用于异步回调返回一个 Object
*/
+ (void)registerCallbackRouteURL:(NSString *)routeURL handler:(FFCallbackRouterHandler)handlerBlock;
/**
判断 URL 是否可被 Route(是否已经注册)
@param URL 要判断的 URL
@return 是否可被 Route
*/
+ (BOOL)canRouteURL:(NSString *)URL;
/**
Route 一个 URL
@param URL 要 Route 的 URL
*/
+ (void)routeURL:(NSString *)URL;
/**
Route 一个 URL,并带上额外参数
@param URL 要 Route 的 URL
@param parameters 额外参数
*/
+ (void)routeURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
/**
Route 一个 URL,可获得返回的 Object
@param URL 要 Route 的 URL
@return 返回的 Object
*/
+ (id)routeObjectURL:(NSString *)URL;
/**
Route 一个 URL,并带上额外参数,可获得返回的 Object
@param URL 要 Route 的 URL
@param parameters 额外参数
@return 返回的 Object
*/
+ (id)routeObjectURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
/**
Route 一个 URL,targetCallBack 可异步回调以返回一个 Object
@param URL 要 Route 的 URL
@param targetCallback 异步回调
*/
+ (void)routeCallbackURL:(NSString *)URL targetCallback:(FFRouterCallback)targetCallback;
/**
Route 一个 URL,并带上额外参数,targetCallBack 可异步回调以返回一个 Object
@param URL 要 Route 的 URL
@param parameters 额外参数
@param targetCallback 异步回调
*/
+ (void)routeCallbackURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters targetCallback:(FFRouterCallback)targetCallback;
/**
Route 一个未注册 URL 时回调
@param handler 回调
*/
+ (void)routeUnregisterURLHandler:(FFRouterUnregisterURLHandler)handler;
/**
取消注册某个 URL
@param URL 要被取消注册的 URL
*/
+ (void)unregisterRouteURL:(NSString *)URL;
/**
取消注册所有 URL
*/
+ (void)unregisterAllRoutes;
/**
是否显示 Log,用于调试
@param enable YES or NO,默认为 NO
*/
+ (void)setLogEnabled:(BOOL)enable;
【备注】
(1)注册 URL
三种 URL 类型:
[FFRouter registerRouteURL:@"protocol://page/routerDetails/:id" handler:^(NSDictionary *routerParameters) {
//Route的URL与本次注册URL匹配时的回调
//routerParameters中包含了传递过来的所有参数
}];
[FFRouter registerRouteURL:@"wildcard://*" handler:^(NSDictionary *routerParameters) {
//Route的URL与本次注册URL匹配时的回调
//routerParameters中包含了传递过来的所有参数
}];
[FFRouter registerRouteURL:@"protocol://page/routerObjectDetails" handler:^(NSDictionary *routerParameters) {
//Route的URL与本次注册URL匹配时的回调
//routerParameters中包含了传递过来的所有参数
}];
可以通过 routerParameters
获取 URL 中的参数,routerParameters[FFRouterParameterURLKey]
为完整的 URL。
三种注册及路由方式:
//注册方式1:
+ (void)registerRouteURL:(NSString *)routeURL handler:(FFRouterHandler)handlerBlock;
//与下面两个 Route 方法配合使用
+ (void)routeURL:(NSString *)URL;
+ (void)routeURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
//注册方式2:
+ (void)registerObjectRouteURL:(NSString *)routeURL handler:(FFObjectRouterHandler)handlerBlock;
//与下面两个 Route 方法配合使用,可同步反向传值
+ (id)routeObjectURL:(NSString *)URL;
+ (id)routeObjectURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters;
//注册方式3:
+ (void)registerCallbackRouteURL:(NSString *)routeURL handler:(FFCallbackRouterHandler)handlerBlock;
//与下面两个 Route 方法配合使用,可异步反向传值
+ (void)routeCallbackURL:(NSString *)URL targetCallback:(FFRouterCallback)targetCallback;
+ (void)routeCallbackURL:(NSString *)URL withParameters:(NSDictionary<NSString *, id> *)parameters targetCallback:(FFRouterCallback)targetCallback;
(2)当需要通过以下方法:
+ (id)routeObjectURL:(NSString *)URL;
路由一个 URL 并获取返回值时,需要使用以下方法注册 URL:
+ (void)registerObjectRouteURL:(NSString *)routeURL handler:(FFObjectRouterHandler)handlerBlock;
并在 handlerBlock 中返回需要返回的 Object,例如:
//注册并返回必要的值
[FFRouter registerObjectRouteURL:@"protocol://page/routerObjectDetails" handler:^id(NSDictionary *routerParameters) {
NSString *str = @“根据需要返回必要的Object”;
return str;
}];
//获取返回的值
NSString *ret = [FFRouter routeObjectURL:@"protocol://page/routerObjectDetails"];
(3)如果想要在路由 URL 后通过异步回调获取返回的 Object,可以使用以下方法注册和路由 URL:
//注册并在必要时间通过回调返回对应 Object
[FFRouter registerCallbackRouteURL:@"protocol://page/RouterCallbackDetails" handler:^(NSDictionary *routerParameters, FFRouterCallback targetCallBack) {
//在必要时候通过 targetCallBack 回调去返回对应 Object
targetCallBack(@"任意Object");
}];
//Route 时通过 ‘targetCallback’ 回调获取返回的对应 Object
[FFRouter routeCallbackURL:@"protocol://page/RouterCallbackDetails?nickname=imlifengfeng" targetCallback:^(id callbackObjc) {
self.testLabel.text = [NSString stringWithFormat:@"%@",callbackObjc];
}];
(4)如果需要传递非常规对象作为参数,如 UIImage
等,可以使用以下方式:
[FFRouter routeURL:@"protocol://page/routerDetails?nickname=imlifengfeng" withParameters:@{@"img":[UIImage imageNamed:@"router_test_img"]}];
如果只需要传递普通参数,可以直接在URL后拼接参数:
[FFRouter routeURL:@"protocol://page/routerDetails?nickname=imlifengfeng&id=666¶meters......"];
随后可以从routerParameters
中获取这些参数。例如:routerParameters[@"nickname"]
2、URL重写
/**
根据设置的 Rules 去 rewrite 一个 URL
@param url 将被 rewrite 的 URL
@return rewrite 后的 URL
*/
+ (NSString *)rewriteURL:(NSString *)url;
/**
添加一个 RewriteRule
@param matchRule 正则匹配规则
@param targetRule 转换规则
*/
+ (void)addRewriteMatchRule:(NSString *)matchRule targetRule:(NSString *)targetRule;
/**
同时添加多个 RewriteRule,格式必须为:@[@{@"matchRule":@"YourMatchRule",@"targetRule":@"YourTargetRule"},...]
@param rules RewriteRules
*/
+ (void)addRewriteRules:(NSArray<NSDictionary *> *)rules;
/**
移除一个 RewriteRule
@param matchRule 将被移除的 matchRule
*/
+ (void)removeRewriteMatchRule:(NSString *)matchRule;
/**
移除所有 RewriteRule
*/
+ (void)removeAllRewriteRules;
【备注】
(1)可以使用正则
添加一条重写规则,例如:要实现打开URL:https://www.taobao.com/search/原子弹
时,将其拦截,改用本地已注册的URL:protocol://page/routerDetails?product=原子弹
。首先添加一条重写规则:
[FFRouterRewrite addRewriteMatchRule:@"(?:https://)?www.taobao.com/search/(.*)" targetRule:@"protocol://page/routerDetails?product=$1"];
随后在打开URL:https://www.taobao.com/search/原子弹
时,将会重写到URL:protocol://page/routerDetails?product=原子弹
。
[FFRouter routeURL:@"https://www.taobao.com/search/原子弹"];
(2)可以通过以下方法同时增加多个规则:
+ (void)addRewriteRules:(NSArray<NSDictionary *> *)rules;
其中rules格式必须为以下格式:
@[@{@"matchRule":@"YourMatchRule1",@"targetRule":@"YourTargetRule1"},
@{@"matchRule":@"YourMatchRule2",@"targetRule":@"YourTargetRule2"},
@{@"matchRule":@"YourMatchRule3",@"targetRule":@"YourTargetRule3"},]
(3)重写规则中的保留字:
- 通过
$scheme
、$host
、$port
、$path
、$query
、$fragment
来获取标准URL的相应部分。通过$url
来获取完整URL - 通过
$1
、$2
、$3
...来获取matchRule
中的正则表达式使用圆括号捕获的参数 $
:原变量的值、$$
:原变量URL编码后的值、$#
:原变量URL解码后的值
例如:对于重写规则(?:https://)?www.taobao.com/search/(.*)
$1=原子弹
$$1=%e5%8e%9f%e5%ad%90%e5%bc%b9
同样,对于重写规则(?:https://)?www.taobao.com/search/%e5%8e%9f%e5%ad%90%e5%bc%b9
$1=%e5%8e%9f%e5%ad%90%e5%bc%b9
$#1=原子弹
2、FFRouterNavigation
考虑到经常使用路由配置UIViewController
之间的跳转,因此增加了额外的工具FFRouterNavigation
,以便更方便地控制UIViewController
之间的跳转。具体使用方法如下:
/**
push 时是否自动隐藏底部TabBar
@param hide 是否自动隐藏,默认为 NO
*/
+ (void)autoHidesBottomBarWhenPushed:(BOOL)hide;
/**
获取当前 ViewController
@return 当前 ViewController
*/
+ (UIViewController *)currentViewController;
/**
获取当前 NavigationViewController
@return return 当前 NavigationViewController
*/
+ (nullable UINavigationController *)currentNavigationViewController;
/**
Push ViewController
@param viewController 被 Push 的 ViewController
@param animated 是否使用动画
*/
+ (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
/**
Push ViewController,可设置当前 ViewController 是否还保留
@param viewController 被 Push 的 ViewController
@param replace 当前 ViewController 是否还保留
@param animated 是否使用动画
*/
+ (void)pushViewController:(UIViewController *)viewController replace:(BOOL)replace animated:(BOOL)animated;
/**
Push 多个 ViewController
@param viewControllers ViewController Array
@param animated 是否使用动画
*/
+ (void)pushViewControllerArray:(NSArray *)viewControllers animated:(BOOL)animated;
/**
present ViewController
@param viewController 被 present 的 ViewController
@param animated 是否使用动画
@param completion 回调
*/
+ (void)presentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^ __nullable)(void))completion;
/**
关闭当前 ViewController,push、present 方式通用
@param animated 是否使用动画
*/
+ (void)closeViewControllerAnimated:(BOOL)animated;
感谢
FFRouter
实现方案参考了以下文章,在此表示感谢!