我正在尝试向我视图中的现有按钮添加手势(滑动)功能,但我无法弄清楚如何将滑动附加到按钮的区域.
所需的效果是有一个按钮,我可以按下以及滑动以产生不同的结果.到目前为止,我正在实现手势的方式将其应用于我的整个视图而不仅仅是按钮.
我觉得这很简单,但它已经让我逃脱了几天 – 我可能只是在寻找错误的东西.
(我将’@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") } }