2014-11-22 196 views
1

我正在嘗試在我的應用程序中使用MMDrawerController,但是我無法在側視圖中使用手勢關閉側抽屜。我在我的應用程序中的其他地方使用了MMDrawerController,並取得了巨大成功,但無法弄清楚爲什麼它在這種情況下不起作用。MMDrawerController無法關閉抽屜

頂級視圖控制器是一個UINavigationController,其默認視圖控制器是MasterViewController(下面的源代碼)。這個類擴展MMDrawerController併爲我想要的配置視圖(中心和右邊,關閉手勢,最大寬度)。中央視圖有一個打開抽屜的按鈕。抽屜打開後,我無法用中央視圖上的手勢將其關閉。我向抽屜中添加了一個按鈕,它可以通過編程關閉抽屜,但我需要能夠在中央視圖上進行製表/平移。

類MasterViewController:MMDrawerController {

override func viewDidLoad() { 
    let centerView = storyboard!.instantiateViewControllerWithIdentifier("CenterControllerName") as? CenterControllerType 
    super.setCenterViewController(centerView, withCloseAnimation: false, completion: nil) 
    let drawer = storyboard!.instantiateViewControllerWithIdentifier("Drawer") as? DrawerType 
    super.rightDrawerViewController = drawer 
    super.setMaximumRightDrawerWidth(200, animated: true, completion: nil) 
    super.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView | MMCloseDrawerGestureMode.TapCenterView 
} 

}

打開抽屜的功能:

@IBAction func drawerButtonPressed(sender: AnyObject) { 
    drawer?.openDrawerSide(MMDrawerSide.Right, animated: true, completion: nil) 
} 

回答

0

我能夠通過放置一個ContainerView作爲唯一的目標,以解決此在我看來,然後從我的ViewController配置MMDrawerContainer。它看起來並不是正確的答案,但從用戶的角度來看,所有的外觀和功能都是正確的。

+0

嘿蘭迪,我有相同的問題,因爲相當多的時間。你能提供更多關於你的解決方案的信息嗎?謝謝 – 2016-01-13 08:39:31

+0

問題在於您的手勢是針對給定的VC定義的,但是當您打開抽屜時,它會將當前的VC更改爲新的VC,並且之前的VC僅顯示,但無法交互與 – 2016-01-13 08:41:24

+0

好吧我修復它,唐娜寫一個答案 – 2016-01-13 08:47:49

0

好了,所以我遇到同樣的問題,我幾乎可以肯定,它來源於此:

guddrawing.png

確定,VC1(與星)是我們的應用程序主頁中,VC2是左邊的抽屜,VC3是DrawerController。

在很長一段時間裏,我試圖把手勢函數放在VC1和VC2中,但只在VC1中打開,並且在VC2中關閉會起作用。 我VC1使用的功能:

let rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("showDrawer:")) 

rightSwipe.direction = .Right 
view.addGestureRecognizer(rightSwipe) 

... 

    func showDrawer(sender: UISwipeGestureRecognizer) { 
    if let m = mmdc { 
     if !m.isLeftDrawerOpen() { 
     m.toggleDrawerSide(MMDrawerSide.Left, animated: true, completion: nil) 
     } 
    } 
    } 

而同樣一個在VC2但與LeftSwipe和closeDrawer。

解決方法是將這兩個函數和手勢識別器都放在VC3(DrawerController)中。

問題來自您的手勢是爲給定的VC定義的事實,但是當您打開抽屜時,它會將當前的VC更改爲新的VC,並且之前的VC僅顯示但不能與...交流。通過將事物放入VC1/VC2的父VC中,可以解決問題。