iPad 应用程序 UIButton 的响应时间
我有一个简单的 UIButton,单击后会播放 1 秒的声音。我希望能够非常快速地单击该按钮并尽可能多次地发出该声音。
我目前已经通过包括来启动并运行它,也许这就是罪魁祸首......另外,我正在深入研究苹果的参考文献,但无法找到有关 UIButton 响应每个事件的速度有多快以及如何响应的信息,如果在所有,我可以控制和操纵这个值。
我应该切换到不同的音频框架,例如“音频工具箱”,还是有办法让我加快速度,或者也许指示一个按钮在第一次按下的操作仍在进行时接受第二次和第三次按下。
干杯!
〜尼尔。
i have a simple UIButton that, once clicked, plays a 1 second sound. i want to be able to click that button really fast and produce that sound as many times as i humanly can.
i currently have this up and running by including the and maybe that is where the culprit is... also, i am digging into apple's references and cannot find the info for how quick is a UIButton to respond to each event and how, if at all, i can control and manipulate this value.
should i switch to a different audio framework like the "audio toolbox" or is there a way for me to speed things up, or perhaps instruct a button to accept a 2nd and 3rd press while the action of the first press is still underway.
cheers!
~nir.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个独立于按钮处理程序方法来播放声音的方法。假设您将其命名为
playSound
。在按钮处理程序中,在后台执行该方法:在播放声音之前,这确实会产生额外的开销来生成线程。如果您想加快速度,请创建一个工作线程池并使用:
创建工作线程池:(
此代码未经测试,可能需要一些调试,但它应该让您朝着正确的方向前进。 )
Create a method to play the sound separate from the button handler method. Let's say you call it
playSound
. In your button handler, execute that method in the background with:That does incur additional overhead to spawn off a thread before it can play the sound. If you want to speed it up a bit more, create a pool of worker threads and use:
To create the pool of worker threads:
(This code is untested and may require some debugging, but it should get you going in the right direction.)