Skip to content

xmbsn/URLManager

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

URLManager

URLManager是为iOS App开发的导航组件。使用URL Scheme管理整个App的ViewController。

安装/配置

把URLManager目录拷贝到你的工程下。

在AppDelegate中初始化Navigator和配置信息

UMgrAppDelegate.m

    self.viewController = [[UMgrDemoViewController alloc] initWithURL:[NSURL URLWithString:@"um://demo"]];
    self.navigator = [[UMNavigator alloc] initWithRootViewController:self.viewController];
    self.navigator.navigationBar.tintColor = [UIColor lightGrayColor];

    [self.navigator setViewControllerName:@"UMgrDemoViewController" forURL:@"um://demo"];
    [self.navigator setViewControllerName:@"UMgrDemoBViewController" forURL:@"um://demob"];

    self.viewController.navigator = self.navigator;
    
    [self.window addSubview:self.navigator.view];

使用

URL管理ViewController

使用URLManager要求所有的ViewControlelr继承自UMViewController,如UMgrDemoViewController。UMViewController继承自UIViewController。 ViewController的初始化方法变为

- (id)initWithURL:(NSURL *)aUrl;

// 或

- (id)initWithURL:(NSURL *)aUrl query:(NSDictionary *)query;

详细配置可参考UMgrDemoViewController和UMgrDemoBViewController

在UMgrDemoViewController中可以通过一下代码调用新的ViewController

UMgrDemoViewController.m

    [self.navigator openURL:[[NSURL URLWithString:@"um://demob/path/aaa"]
                             addParams:[NSDictionary dictionaryWithObjectsAndKeys:
                                        @"va", @"ka",
                                        @"vb", @"kb",
                                        nil]]];

// 或

    [self.navigator openURL:[NSURL URLWithString:@"um://demob/?a=b"]
                  withQuery:[NSDictionary dictionaryWithObjectsAndKeys:
                             [NSArray arrayWithObjects:@"1", @"2", nil], @"q_key", nil]];

在每一个ViewController中,通过实现

- (BOOL)shouldOpenViewControllerWithURL:(NSURL *)aUrl;
- (void)openedFromViewControllerWithURL:(NSURL *)aUrl;

可以捕捉到打开一个新的ViewController的动作。

通过滑动打开ViewController

继承自UMViewController的ViewController支持 Path 首页一样的左右滑动,左右的View也通过单独ViewController控制,并用URL管理。

在ViewController中实现 UMSlideDelegate 的方法即可实现

UMgrDemoViewController.h

#import "UMViewController.h"

@interface UMgrDemoViewController : UMViewController 

@end

UMgrDemoViewController.m

- (NSURL *)leftViewControllerURL
{
    return [NSURL URLWithString:@"um://demob"];
}

- (NSURL *)rightViewControllerURL
{
    return [NSURL URLWithString:@"um://demoweb"];
}

- (CGFloat)rightViewWidth {
    return 200.0f;
}

- (void)willOpenLeftViewController
{
    NSLog(@"will open left view controller.");
}

也可以通过调用 open 方法打开左右的ViewController

UMgrDemoViewController.m

[self openRightViewController];
// 或
[self openLeftViewController];

调用 backToInitialStatus 方法可以使滑动后的 ViewController 恢复

UMgrDemoBViewController.m

[self backToInitialStatus];

About

iOS ViewController URL Scheme

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published