国家开始和结束没有被触发

时间:2016-09-02 14:36:12

标签: ios swift uitapgesturerecognizer

我试图制作拍照和录制视频的按钮。当长按时,它将进行记录,1次点击将拍照。当按下按钮时,我想将其转换为创建效果。但是开始和结束都没有被触发,因为它没有改变?

func centerButtonPressedDown(sender: UITapGestureRecognizer) {

    if !pictureTaken {
        delegate?.didLongTapCameraButton()


    } else {

    }



}

func centerButtonClicked(sender: UITapGestureRecognizer) {


    if sender.state == .began {
        self.centerButton.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
    } else if sender.state == .ended {
        self.centerButton.transform = CGAffineTransform.identity
    }





}

CenterButton

    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(centerButtonClicked))  //Tap function will call when user tap on button
    let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(centerButtonPressedDown))
    tapGesture.numberOfTapsRequired = 1
    centerButton.addGestureRecognizer(tapGesture)
    centerButton.addGestureRecognizer(longGesture)

1 个答案:

答案 0 :(得分:0)

我首先尝试了你的代码兄。它显示了我的错误。然后我修改了代码它运行正常。

let tapGesture = UITapGestureRecognizer(target: self, action:Selector("centerButtonClicked:"))  //Tap function will call when user tap on button
let longGesture = UILongPressGestureRecognizer(target: self, action:Selector("centerButtonPressedDown:"))
tapGesture.numberOfTapsRequired = 1
centerButton.addGestureRecognizer(tapGesture)
centerButton.addGestureRecognizer(longGesture)


func centerButtonPressedDown(sender: UILongPressGestureRecognizer) {

    if sender.state == .Began {
        print("long press began")
    }
    else if sender.state == .Ended {
        print("long press Ended")
    }
}

func centerButtonClicked(sender: UITapGestureRecognizer) {
     print("tap is detected")
}

单击按钮时,打印结果为

 tap is detected

当我长按按钮时,打印结果为

 long press began
 long press Ended