4
我想將手勢(滑動)功能添加到我的視圖中的現有按鈕,但我無法弄清楚如何將滑動按鈕附加到按鈕的區域。將手勢添加到快捷按鈕中
預期的效果是讓我可以按下按鈕以及輕掃以產生不同的結果。到目前爲止,我正在實施手勢的方式將其應用於我的整個視圖,而不僅僅是按鈕。
我有一種感覺,它很簡單,但它已經逃離了我幾天 - 我可能只是在尋找錯誤的東西。
(我指定 '@IBOutlet VAR swipeButton:UIButton的' 到BTW我的按鈕)
下面代碼:
class ViewController: UIInputViewController {
@IBOutlet var swipeButton: UIButton!
let swipeRec = UISwipeGestureRecognizer()
override func viewDidLoad() {
super.viewDidLoad()
self.loadInterface()
var swipeButtonDown: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "ButtonDown")
swipeButtonDown.direction = UISwipeGestureRecognizerDirection.Down
self.view.addGestureRecognizer(swipeButtonDown)
}
@IBAction func buttonPressed(sender: UIButton) {
var proxy = textDocumentProxy as UITextDocumentProxy
proxy.insertText("button")
}
func buttonDown(){
var proxy = textDocumentProxy as UITextDocumentProxy
proxy.insertText("swipe")
}
}
我將它設置在第13行如下 - 它總是崩潰,所以我肯定做錯了什麼:d self.swipeButton.addGestureRecognizer(swipeButtonDown) – glasstongue 2015-01-21 05:26:24
顯示崩潰日誌在題。 – 2015-01-21 05:28:06
我編輯了錯誤的[這裏:var swipeButtonDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target:self,action:「ButtonDown」)]並且沒有撤消 - 像魅力一樣!我喜歡你,但我是一個低調的新手 - 乾杯! – glasstongue 2015-01-21 05:41:30