我在一个需要更多即时体验的应用程序中遇到了很多延迟。
我有一个简单的应用程序,可以左右切换。这是一个秋千,当一端向上时,另一端向下。你应该用两个手指在屏幕上轻敲,就像你刚刚摆弄它一样。这应该是对多动症的一种帮助。
我有两张左边和右边的大图。我已经在图像上识别了一个手势,我检查了敲击的坐标,以确定您是点击右侧向下还是点击左侧。我还在使用AudioServicesPlayAlertSound在触摸begin时产生一个小的弹出振动,以努力给用户一点反馈刺激。
在我的测试中,如果我快速点击,似乎我在切换上得到了积压的点击。震动发生在敲击结束后很久,所以它感觉没用。有时,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
}
}
}另一个想法--以按钮的形式实现会不会更快?手势识别器是不是很慢?我绘制图像状态的方式是否消耗了错误的类型处理能力?
发布于 2016-12-16 18:54:29
就像你在代码中犯了错误一样。您想要创建tap识别器,但您创建了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)https://stackoverflow.com/questions/41179662
复制相似问题