我把視圖控制器當作UIPageViewController裏面。如何選擇正確的UIGestureRecognizer?
使用pageviewcontroller我可以左右搖擺以轉到其他VC。有用!
所以,我添加sideBarMenu後。當加入這個菜單我使用此代碼添加手勢識別:
var menuViewController: UIViewController! {
didSet {
self.exitPanGesture = UIPanGestureRecognizer()
self.exitPanGesture.addTarget(self, action:"handleOffstagePan:")
self.sourceViewController.view.addGestureRecognizer(self.exitPanGesture)
}
這裏sourceViewController是我原來的VC。
問題是當我嘗試滑動(爲了關閉菜單),pageViewController滑動工作。
我想禁用pageViewController刷卡並打開菜單時啓用新的刷卡功能。當菜單關閉時做相反的操作。
附加代碼:
func handleOffstagePan(pan: UIPanGestureRecognizer){
println("dismiss pan gesture recognizer")
let translation = pan.translationInView(pan.view!)
let d = translation.x/CGRectGetWidth(pan.view!.bounds) * -0.5
switch (pan.state) {
case UIGestureRecognizerState.Began:
self.interactive = true
self.menuViewController.performSegueWithIdentifier("dismisMenu", sender: self)
break
case UIGestureRecognizerState.Changed:
self.updateInteractiveTransition(d)
break
default:
self.interactive = false
if d > 0.1 {
self.finishInteractiveTransition()
}else {
isMenuVisible = false
self.cancelInteractiveTransition()
}
}
}
考慮你的問題我認爲目前handleOffstagePan事件不會被觸發,對嗎? –
是的,你是!我找到了解決方案,而不是編寫sourviewcontroller = PageViewController,我寫了sourveviewcontroller = PageContentViewController。現在手勢識別器起作用了。我有新的問題,現在我不能左滑,右擊我的pageviewcontroller,我需要添加舊的手勢識別器,或刪除我添加的新的(關閉菜單) –
刪除手勢識別器,它被添加到self.sourceViewController在旁邊handleOffstagePan事件 –