TAGS :Viewed: 9 - Published at: a few seconds ago

[ state began and ended not being triggered ]

I'm trying to make a button for Taking pictures and recording videos. When a long press is made it will record and 1 tap will take a picture. when button is being pressed i want to transform it to create a effect. however the began and ended is not being triggered since it is not transforming?

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)

Answer 1


I tried your code brother first.It shows me error.Then i modified the code it works fine.

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

When I single tap the button the printed result is

 tap is detected

When I long press the button the printed result is

 long press began
 long press Ended