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 を使用したくありません。そうしなければならない場合を除き、それは必要以上の作業のように思えます。