所以我正在使用这个'SwipeViewController'(https://github.com/fortmarek/SwipeViewController),这真的给了我想要的效果,但问题是它只作为主导航控制器运行,我想让它在容器视图中工作因为我想在个人资料菜单中使用它作为这个社交应用程序,就像推特“我的推文”,“喜欢”,“重新发布”......
所以我需要这个......
所以只是一个解释,要使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控制器中工作。
答案 0 :(得分:0)
我昨晚使用这里的教程做了类似的事情:
https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/
我的相关代码如下。我从容器视图创建了一个IBOutlet到我的ViewController,然后下面的代码将相应的视图控制器添加到容器视图中,具体取决于我Bool
buttonDefault
的设置。确保将子视图添加到容器视图,而不是视图控制器中的主视图。
@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)
}
}
添加此内容后,只需在updateView()
中调用viewDidLoad
,即可在用户选择要查看的新选项时随时调用@(
。
我希望这会有所帮助。