我有一个带有 3 个标签的应用程序。我想向右或向左滑动以转到另一个选项卡。
我的代码:
//Swipe Between Tabs
let rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
let leftSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
rightSwipe.direction = .Right
leftSwipe.direction = .Left
view.addGestureRecognizer(rightSwipe)
view.addGestureRecognizer(leftSwipe)
//end Swipe
执行它的功能是
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .Left) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("PantryList")
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: true, completion: nil)
}
if (sender.direction == .Right) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ToDoList")
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: true, completion: nil)
}
}
我的问题是使用滑动时底部的 tabBarController 消失了。从我发现它与“presentViewController”方法有关。这是导致它的原因吗?有没有办法在不丢失 tabBarController 的情况下做到这一点?如果不需要,我真的不想使用 prepareForSegueWithIdentifier。除非必须这样做,否则这似乎比需要完成的工作更多。