私はViewController
の中で右にスワイプしたいと思っています。これは別のビューコントローラを表示します、CommunitiesViewController
。Swift 3で新しいView Controllerを表示するには右にスワイプする方法は?
私は他のスレッドで見て、私は、彼らがこれは私が私のViewController
に使用していたコードであるスウィフト2.
のためのものであると考えているものの、これを行うのいくつかの方法を発見した:私が持っている
override func viewDidLoad() {
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: Selector(("respondToSwipeGesture")))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
}
func respondToSwipeGesture(gesture: UIGestureRecognizer) {
print ("Swiped right")
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
//change view controllers
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController = storyBoard.instantiateViewController(withIdentifier: "CommunitiesID") as! CommunitiesViewController
self.present(resultViewController, animated:true, completion:nil)
default:
break
}
}
}
は、 CommunitiesViewController
のストーリーボードIDはCommunitiesID
です。
しかし、これは動作しないとアプリがクラッシュし、私は次のエラーで右スワイプする場合:
libc++abi.dylib: terminating with uncaught exception of type NSException