gpt4 book ai didi

ios - 修改 SwipeViewController Pod 以在 ContainerView 中运行

转载 作者:行者123 更新时间:2023-11-30 12:13:51 26 4
gpt4 key购买 nike

我正在使用这个 pod 'SwipeViewController' ( https://github.com/fortmarek/SwipeViewController ),它确实给了我想要的效果,但问题是它只作为主导航 Controller 运行,我希望它在容器 View 中工作,因为我想在个人资料菜单中将其用于此社交应用程序,就像 Twitter 中的“我的推文”、“喜欢”、“转发”...

例如我需要这个...

https://camo.githubusercontent.com/f4eb2a8ba0a11e672d02a1ef600e62b5272a7843/687474703a2f2f696d6775722e636f6d2f5344496b6634622e676966

在这里工作:
Img 1
Img 2

所以只是一个解释,要使 pod 工作,您需要将这行代码添加到 appDelegate

let pageController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
let navigationController = YourViewControllerName(rootViewController: pageController)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()

它使用 SwipeController 创建一个新窗口,我需要一种方法使其在 View Controller 中工作。

最佳答案

我昨晚使用这里的教程做了类似的事情:

https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/

我的相关代码如下。我从容器 View 到 ViewController 创建了一个 IBOutlet,然后下面的代码根据名为 buttonDefaultBool 设置将适当的 View Controller 添加到容器 View 。确保将 subview 添加到容器 View 中,而不是 View Controller 中的主视图。

@IBOutlet weak var containerView: UIView!

// MARK: Container View
// https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/
lazy var remoteViewController: RemoteViewController = {
// Load Storyboard
let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)

// Instantiate View Controller
var viewController = storyboard.instantiateViewController(withIdentifier: "RemoteViewController") as! RemoteViewController

// Add View Controller as Child View Controller
self.add(asChildViewController: viewController)

return viewController
}()

lazy var gestureRemoteViewController: GestureRemoteViewController = {
// Load Storyboard
let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)

// Instantiate View Controller
var viewController = storyboard.instantiateViewController(withIdentifier: "GestureRemoteViewController") as! GestureRemoteViewController

// Add View Controller as Child View Controller
self.add(asChildViewController: viewController)

return viewController
}()

func add(asChildViewController viewController: UIViewController) {
// Add Child View Controller
addChildViewController(viewController)

// Add Child View as Subview
containerView.addSubview(viewController.view)

// Configure Child View
viewController.view.frame = containerView.bounds
viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

// Notify Child View Controller
viewController.didMove(toParentViewController: self)
}

func remove(asChildViewController viewController: UIViewController) {
// Notify Child View Controller
viewController.willMove(toParentViewController: nil)

// Remove Child View From Superview
viewController.view.removeFromSuperview()

// Notify Child View Controller
viewController.removeFromParentViewController()
}

func updateView() {
let settings = Settings()

if settings.buttonDefault {
remove(asChildViewController: gestureRemoteViewController)
add(asChildViewController: remoteViewController)
} else {
remove(asChildViewController: remoteViewController)
add(asChildViewController: gestureRemoteViewController)
}
}

添加此内容后,只需在 viewDidLoad 中调用 updateView() 即可,并且只要用户选择要查看的新选项即可。

我希望这有帮助。

关于ios - 修改 SwipeViewController Pod 以在 ContainerView 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45677041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com