gpt4 book ai didi

ios - 状态开始和结束未被触发

转载 作者:行者123 更新时间:2023-11-30 13:06:33 25 4
gpt4 key购买 nike

我正在尝试制作一个用于拍照和录制视频的按钮。长按即可录制,轻按一下即可拍照。当按下按钮时,我想对其进行变换以创建效果。但是开始和结束没有被触发,因为它没有转换?

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
}





}

中心按钮

    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)

最佳答案

我先尝试了兄弟的代码。它显示了错误。然后我修改了代码,它工作正常。

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

关于ios - 状态开始和结束未被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39294980/

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