2016-12-28 74 views
0

我無法使用手勢識別器設置'enabled'屬性。我嘗試通過編程方式創建識別器,並在Xcode中添加@IBAction,並通過控制拖動代碼將其連接。如何在Swift中爲手勢識別器設置'enabled'屬性

我嘗試使用性質是這樣的:

swipeUpOccurred(swipeUp: UISwipeGestureRecognizer).enabled = false 

但它顯示錯誤:

Value of type '(UISwipeGestureRecognizer) ->' does not have member 'enabled'

回答

3

您正在嘗試設置isEnabled上的UIGestureRecognizer作用。而不是你需要創建UIGestureRecognizer的出口,如果你想訪問它在你的ViewController,所以創建一個特定類型的手勢出口然後設置isEnabled屬性true/false當你需要enable/disabled它。

@IBOutlet var swipeGest: UISwipeGestureRecognizer! 

現在使用isEnabled屬性。

self.swipeGest.isEnabled = false 
+0

它原來是這麼簡單...謝謝! –

+0

@AntonPlatonov歡迎伴侶:) –

0

它改名。改爲嘗試isEnabled

swipeUpOccurred(swipeUp: UISwipeGestureRecognizer).isEnabled = false 
+0

在這種情況下,警告是:元組類型的值「()」沒有成員「的IsEnabled」 –