Magellan 1.1.2

Magellan 1.1.2

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2017年6月
SwiftSwift 版本3.0
SPM支持 SPM

pjechris 维护。



Magellan 1.1.2

  • pjechris 和 akane

Nabigeta

Nabigeta 提供了简单的 API 来声明导航路由。兼容 trait 环境。

使用

在文件中声明您的路由,例如您的 AppDelegate

import Nabigeta

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  var navigation: Navigation! = nil

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.navigation = Navigation(traitProvider: self.window!)

    self.navigation.router = { context in
        switch(context) {
          case is Author:
            return Route(AuthorViewController.self)

          case is Book:
            return Route(BookViewController.self)
              .present { trait in
                  switch(trait.horizontalClass, trait.verticalClass) {
                    case (.Compact, .Compact):
                      return PresentationPush()
                    default:
                      return PresentationModal()
                  }
              }
        }
    }
  }
}

class AuthorViewController : UIViewController, Navigable {
    func didNavigate(to author: Author) {
      print("Navigated to /(author.name) controller")
    }
}

class BookViewController {
  func didTapAuthor() {
    self.navigate(to: self.author) // AuthorViewController is displayed!
  }
}

高级使用

表示

Nabigeta 提供了一些默认的表示策略

  • PresentationPush
  • PresentationModal
  • PresentationPopover
  • PresentationSegue

如果其中任何一个不符合您的需求,您可以通过创建一个实现 PresentationStrategy 协议的类/结构来提供自己的自定义表示。

停止导航

后退导航

您可以从源控制器取消导航

  bookViewController.navigateBack() // come back to BookViewController

您还可以从目标控制器停止导航

  authorViewController.navigationTerminated(status: .Canceled) // dismiss AuthorViewController

当导航停止时,您还可以被告知

  bookViewController
    .navigate(to: self.author)
    .onTerminate { status in
      if status == .Canceled {
        print("author controller cancelled")
      }
    }