拖动手势和弹出警报振动的延迟
问题描述:
我在需要更快速感觉的应用程序中收到很多延迟。拖动手势和弹出警报振动的延迟
我有一个简单的应用程序,左右切换。这是一个跷跷板,当一端结束时,另一端结束。你应该使用两个手指,然后点击屏幕,就像你只是在烦躁一样。它应该是对ADHD的一种帮助。
我有两个左右状态的大图像。我已经在图像上识别了一个手势,并检查了水龙头的坐标,以确定是否轻敲了右侧向下或向左。我也在使用AudioServicesPlayAlertSound来触发一个小的流行振动,以便为用户提供一点反馈激励。
在我的测试中,如果我快速点击,看起来我会在切换点上积压点击。水龙头结束后振动发生,所以感觉没用。有时UI图像会在图像之间切换。
override func viewDidLoad() {
super.viewDidLoad()
let imageView = Seesaw
let tapGestureRecognizer = UILongPressGestureRecognizer(target:self, action: #selector(SeesawViewController.tapped));
tapGestureRecognizer.minimumPressDuration = 0
imageView?.addGestureRecognizer(tapGestureRecognizer)
imageView?.isUserInteractionEnabled = true
}
func tapped(touch: UITapGestureRecognizer) {
if touch.state == .began {
if(vibrateOn){
AudioServicesPlaySystemSound(1520)
}
let tapLocation = touch.location(in: Seesaw)
if(tapLocation.y > Seesaw.frame.height/2){
print("Go Down")
Seesaw.image = UIImage(named:"Down Seesaw");
seesawUp = false
} else if (tapLocation.y < Seesaw.frame.height/2){
print("Go Up");
Seesaw.image = UIImage(named:"Up Seesaw");
seesawUp = true
}
}
}
另一个想法 - 将它作为按钮来实现会更快吗?手势识别器是否慢?我正在绘制图像状态消耗错误类型处理能力的方式吗?
答
像你一样在你的代码中犯了错误。你想创建自来水识别,但所创建UILongPressGestureRecognizer
请从
let tapGestureRecognizer = UILongPressGestureRecognizer(target:self, action: #selector(SeesawViewController.tapped))
改线
let tapGestureRecognizer = UITapGestureRecognizer(target:self, action: #selector(SeesawViewController.tapped))
或者您可以添加透明的按钮,把你的代码,它的处理器
// onDown will fired when user touched button(not tapped)
button.addTarget(self, action: #selector(onDown), for: .touchDown)
当我运行水龙头识别器时,按钮没有下降,震动没有happ直到手指脱落,这使得延迟更加严重。 – kwaight
哦。现在就了解你。也许你应该尝试透明按钮。 –