ios - 来自 GitHub 的 SwipeNavigationController 框架如何实现

标签 ios swift uinavigationcontroller snapchat

所以我今天的问题是如何添加一个类似于 Snapchat 的 View ,您可以使用手势滑动到其他 View :左、上、下、右。我正在尝试使用这个 framework但我不确定如何真正实现它,因为他们没有提供示例项目。我的应用程序的布局是我有一个注册/登录 View Controller ,从那里我希望它转到另一个 View (蓝色),这就是我想要具有上述不同手势的 View 。 `导入 UIKit 导入 SwipeNavigationController

class BlueViewController: UIViewController {


let orangeVC = OrangeView()

let pinkVC = PinkView()
let greenVC = GreenView()
let purpleVC = PurpleView()



override func viewDidLoad() {



    let swipeNavigationController = SwipeNavigationController(centerViewController: self)
    swipeNavigationController.topViewController = self.pinkVC
    swipeNavigationController.bottomViewController = self.purpleVC
    swipeNavigationController.leftViewController = self.greenVC
    swipeNavigationController.rightViewController = self.orangeVC





    view.backgroundColor = UIColor.facebookBlueColor
   }
}'

我也没有在这个项目中使用 Storyboard。

最佳答案

SwipeNavigationController 是一个 UIViewController,可以推送到堆栈上或与任何其他 UIViewController 一样呈现。无论您在何处创建和呈现 BlueViewController,都应该创建 SwipeNavigationController 作为包含 BlueViewController 和所有方向 View Controller 的顶级对象。 BlueViewController 和所有其他方向不应该知道有关 SwipeViewController 的任何信息。 BlueViewController 和所有其他方向不应该互相了解任何信息。 SwipeNavigationController 是顶级 View Controller ,与方向关联的所有 View Controller 都是其 subview Controller 。我假设您的流程中的某个位置有一个导航 Controller 来插入 SwipeNavigationController。在这种情况下,无论您想要触发推送,您都会有类似的方法。我将其称为 nextTapped,但我确信您的代码中会有所不同:

func nextTapped() {
    let swipeNavigationController = SwipeNavigationController(centerViewController: BlueViewController())
    swipeNavigationController.topViewController = PinkViewController()
    swipeNavigationController.bottomViewController = PurpleViewController()
    swipeNavigationController.leftViewController = GreenViewController()
    swipeNavigationController.rightViewController = OrangeViewController()

    navigationController?.pushViewController(swipeNavigationController, animated: true)
}

然后从 BlueViewController 中的 viewDidLoad 中删除除设置背景颜色的行之外的所有内容。这将创建带有所有方向 View Controller 的 SwipeNavigationController,保持 BlueViewController 为中心,然后将其推送到 View Controller 堆栈上。如果 View Controller 中没有在 SwipeNavigationController 之前显示的 UINavigationController,您可以通过将最后一行替换为以下内容来以模态方式呈现它:

present(swipeNavigationController, animated: true, completion: nil)

关于ios - 来自 GitHub 的 SwipeNavigationController 框架如何实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51181636/

相关文章:

ios - UIScrollView 是否仅适用于嵌入在导航控件中的 View Controller ?

iphone - 更新另一个 View Controller 中的 UILabel

ios - CollectionView Segue 在接收 ViewController 时发现 nil

ios - 使用 CocoaPods 安装的库的正确方法是什么?

swift - 如何在不丢失 Swift 精度的情况下初始化 Decimal

ios - UIcollectionView Reloaddata 在显示实际数据之前显示其下方行中的一些随机数据几分之一秒

ios - Swift:实例化 View Controller 以在当前导航堆栈中进行自定义转换

ios - 使用 Xcode 上的 App 和扩展复制 WatchOS2 的目标

android - 使用带有导航器的滑动菜单的 Onsen-UI

ios - PSCollectionView 调用委托(delegate)