我希望能夠在我的ViewController
中向右滑動,這將顯示另一個視圖控制器,CommunitiesViewController
。如何向右滑動以在Swift 3中顯示新的View Controller?
我已經看過其他線程上,發現這樣做的某些方面,但我相信他們是雨燕2.
這是我用我ViewController
代碼:
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