2014-11-23 79 views
1

我有一個平底鍋的手勢,我需要檢查手勢何時開始。在Objective-C,你可以使用過載gestureRecognizerShouldBegin與UIPanGestureRecognizer在迅速

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 

,並有可能與UIPanGestureRecognizer

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer 

但在迅疾

override func gestureRecognizerShouldBegin(gestureRecognizer: UIPanGestureRecognizer) -> Bool { 

重載它不工作,並返回

重寫方法與選擇器'gestureRecognizerShouldBegin:'具有不兼容的類型'(UIPanGestureReco gnizer) - > Bool'

如何在swift中重載此方法?

回答

0

刪除覆蓋,不要忘記添加UIGestureRecognizerDelegate擴展。

您可以在類的底部添加它

class YourViewController: UIViewController { 
    // You class declaration 
} 

extension YourViewController: UIGestureRecognizerDelegate { 
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool { 
     // 
     return true 
    } 
} 
+0

你並沒有真正回答問題是'如何超載手勢識別器應該爲PanGestures開始' – Macistador 2015-05-20 13:44:10

2

你並不需要重載的方法,你可以這樣做,而不是:

override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool { 
    if let panGesture = gestureRecognizer as? UIPanGestureRecognizer { 
     return ... 
    } 
    else { 
     return ... 
    } 
}