我有一个带有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。除非那是必须要做的,否则这似乎是需要完成的工作。
最佳答案
if (sender.direction == .Right) {
self.navigationController.tabBarController.selectedIndex = 1
}
关于ios - 使用滑动手势时TabController消失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35062009/