我希望能够检测到印刷机何时开始,这样我只能在按下时执行操作,在印刷机结束时停止该操作.
我知道在UILabels上有一个pressBegan功能,但我不知道如何使用它,似乎无法找到示例.
您可以使用UILongPressGestureRecongizer.
在viewController的viewDidLoad方法中初始化pressGestureRecongizer并将其添加到标签:
let pressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "handlePress:") label.addGestureRecognizer(pressGestureRecognizer)
然后定义handlePress函数
func handlePress(sender: UILongPressGestureRecognizer) { if sender.state == UIGestureRecognizerState.Began { // handle start of pressing } else if sender.state == UIGestureRecognizerState.Ended { // handle end of pressing } }