问题描述
我有一个可以录制语音留言的按钮。长按后,我创建一个新视图,可以在其中移动另一个按钮。但是,如果不再次轻按,则平移手势识别器将无法正常工作。那么,您能告诉我如何将手势识别器从一个按钮转移到另一个按钮吗? 因此,我想使用2种方法。
@objc func recordTapped(sender: UILongPressGestureRecognizer){
textInput.isHidden = true
self.view.addSubview(audioPlayerView)
audioPlayerView.setAudioPlayer()
timer = Timer.scheduledTimer(timeInterval: 0.0,target: self,selector: #selector(updateTimer),userInfo: NSDate(),repeats: true)
startRecording()
self.area.backgroundColor = #colorLiteral(red: 0.2392156869,green: 0.6745098233,blue: 0.9686274529,alpha: 0.7026969178)
UIView.animate(withDuration: 2.0,delay: 0,options: [.repeat,.autoreverse],animations: {
self.area.backgroundColor = #colorLiteral(red: 0,green: 0.1071770917,blue: 0.3669734589,alpha: 0.6900149829)
},completion: { (success) in
})
buttonToPlayAudio.isHidden = false
addImageButton.isHidden = true
}
第二个手势是用于新视图
@objc func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
//this method i want to call from prevIoUs button
}
解决方法
您需要将手势识别器添加到公共父视图。调用时,检查手指是否在目标按钮内。然后添加视图,当用户松开手指时,检查它的位置。