是否可以使用UIGestureRecognizer捕获触地得分和长按?
func gestureSetup() {
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tapButton:")
tapTempoButton.addGestureRecognizer(tapGestureRecognizer)
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: "longPressed:")
longPressRecognizer.minimumPressDuration = 1.0
tapTempoButton.addGestureRecognizer(longPressRecognizer)
}
func tapButton(sender: UITapGestureRecognizer) {
// On touch down update UI and play sound
}
答案 0 :(得分:0)
示例:UITextLabel上的手势 //在Label上调用 let rotationGesture = UIRotationGestureRecognizer(target:self,action:“handleRotation:”) rotationGesture.delegate = self
let tapToDeleteTextGesture = UITapGestureRecognizer(target: self, action: "tapToDeleteText:")
tapToDeleteTextGesture.numberOfTapsRequired = 2
textLabel?.addGestureRecognizer(rotationGesture)
textLabel?.addGestureRecognizer(tapToDeleteTextGesture)
func handleRotation(recognizer: UIRotationGestureRecognizer){
let state = recognizer.state
if (state == UIGestureRecognizerState.Began || state == UIGestureRecognizerState.Changed){
if let view = recognizer.view {
view.transform = CGAffineTransformRotate(view.transform, recognizer.rotation)
recognizer.rotation = 0
}
}
}
func tapToDeleteText(recognizer: UITapGestureRecognizer){
if let view = recognizer.view {
view.removeFromSuperview()
}
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
添加添加longPressGesture,您将被设置。