简体   繁体   English

iPhone-强制按钮以编程方式确认触摸

[英]iphone - forcing button to acknowledge touch programmatically

When you touch a UIButton it hides for a fraction of second and then it executes its action. 当您触摸UIButton时,它会隐藏一秒钟,然后执行其动作。 This fast "blink" is the feedback the user needs to know that the button has been clicked. 这种快速的“闪烁”是用户需要知道按钮已被单击的反馈。

In the project I am doing, I need to select the button programmatically, as if the user had clicked it. 在我正在做的项目中,我需要以编程方式选择按钮,就像用户单击它一样。 In other words, the same behavior has the button had been clicked by the user... a fast blink and execution of its action. 换句话说,用户单击按钮的行为相同...快速闪烁并执行其操作。

Is this possible to do? 这可能吗?

thanks for any help. 谢谢你的帮助。

The change in the appearance of the button is effected by setting the button's highlighted property. 通过设置按钮的highlighted属性,可以改变按钮的外观。 The property is automatically set to YES when the user touches down on the button, and back to NO when she releases. 当用户按下按钮时,该属性自动设置为YES当用户释放按钮时,该属性自动设置为NO

The highlighted property is writable, so you can set it YES yourself to simulate a touch down. highlighted属性是可写的,因此您可以将其设置为YES以模拟触地。 You'll probably want to use +[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] to set it back to NO after a short interval. 您可能要使用+[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] ,在短间隔后将其设置回NO

It is pretty simple, and probably there is a better solution. 这很简单,也许有更好的解决方案。 First, use images to your button, and when you have to fire the button, you just change the button's image in the normal state to the pressed image, and after that, replace it back to the original. 首先,对按钮使用图像,当您必须触发按钮时,只需将正常状态下的按钮图像更改为按下的图像,然后将其替换回原始图像即可。 You can simply do it with a timer. 您只需使用计时器即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM