UIKit中,如何检测,当UISlider已停止移动但尚未公布 [英] In UIKit, how to detect when a UISlider has stopped moving but has not been released

查看:97
本文介绍了UIKit中,如何检测,当UISlider已停止移动但尚未公布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要当滑块移动到只起到了良好的效果。

I have a sound effect that I want to only play when the slider is moving.

目前我有playSound方法火灾时,UISlider发送值已更改的事件。

Currently I have the playSound method fire when the UISlider is sending Value Changed events.

我需要一种方法来检测时不被移动滑块,但尚未发布。

I need a way to detect when the slider is not being moved, yet hasn't been released.

我想我可以使用控制事件是超一流的工作出了时间,但我不知道怎样来检测它们。

I think I can use the Control Events of it's super class to work out the timing but I don't see how to detect them.

任何想法?

推荐答案

如果我理解正确,你想保留只要播放声音的滑块被触摸,无论是移动还是不行。要做到这一点,注册一个方法作为目标UIControlEventTouchDown(也许UIControlEventTouchDragInside)事件,另一个用于UIControlEventTouchDragExit / TouchUpOutside / TouchUpInside / TouchCancel的某种组合(取决于你的需要)。第一种方法开始播放的声音,第二个停止。

If I understand you correctly, you want to keep playing the sound as long as the slider is touched, whether it's moving or not. To do this, register one method as the target for UIControlEventTouchDown (and perhaps UIControlEventTouchDragInside) events and another for some combination of UIControlEventTouchDragExit/TouchUpOutside/TouchUpInside/TouchCancel (depending on what you need). The first method starts playing the sound and the second one stops it.

如果您想要播放的其他的声音时,滑块仍感动,但不动,我会建议您每次接收时间启动定时器触地得分/ ValueCahanged /等事件:

If you want to play another sound when the slider is still touched but not moving, I would recommend starting a timer each time you receive a TouchDown/ValueCahanged/etc event:

self.touchTimer = [NSTimer scheduledTimerWithTimeInterval: kDelay
                                                target:self
                                              selector:@selector(noMovement:)
                                              userInfo:nil
                                               repeats:NO];

之后,当收到另一个连的ValueChanged,你取消计时器和触发另一个(或更好,重新安排原一)。当定时器触发,这意味着用户没有移动,因为kDelay滑块,可以改变声音正在播放。 (您需要取消计时器,当你得到一个TouchUpInside /外部事件了。)

Then, whenever you receive another ValueChanged even, you cancel the timer and trigger another (or, better, reschedule the original one). When the timer triggers, it means the user hasn't moved the slider since kDelay, and you can change the sound being played. (You need to cancel the timer when you get a TouchUpInside/Outside event too.)

这篇关于UIKit中,如何检测,当UISlider已停止移动但尚未公布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆