gpt4 book ai didi

ios - 快速向按钮添加手势

转载 作者:搜寻专家 更新时间:2023-10-30 22:10:46 25 4
gpt4 key购买 nike

我正在尝试向我 View 中的现有按钮添加手势(滑动)功能,但我不知道如何将滑动附加到按钮区域。

期望的效果是有一个按钮,我可以按下和滑动来产生不同的结果。到目前为止,我实现手势的方式将它应用于我的整个 View ,而不仅仅是按钮。

我觉得它很简单,但我已经逃避了几天 - 我可能只是在寻找错误的东西。

(顺便说一句,我正在将“@IBOutlet var swipeButton: UIButton!”分配给我的按钮)

代码如下:

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")
}

}

最佳答案

如果你想将 swipeGesture 添加到 Button 中,请按以下方式进行:

self.yourButton.addGestureRecognizer(swipeButtonDown)

而且您发送的选择器也有错误,应该是这样的:

var swipeButtonDown: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "buttonDown")

ButtonDown 更改为 buttonDown

关于ios - 快速向按钮添加手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28059381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com