每秒多次更改 UIButton 背景图像

发布于 2024-08-27 07:47:55 字数 777 浏览 6 评论 0原文

我目前正在使用 iPhone SDK。

我有一个 NSTimer 可以更改 UIButton 的背景图像。 一旦完成,它将再次触发相同的操作(重置 NSTimer)预定的次数。

我的问题是,如果我的 NSTimer 设置为每秒执行多次。 (例如 0.75)背景图像不会改变。

我正在使用 NSLog 来检查事件是否触发。但按钮图像将保持其原始状态。

有什么方法可以使背景图像的更改频率超过每秒一次吗?

这是我的计时器:

[NSTimer scheduledTimerWithTimeInterval: tmpLvlSpeed
                                     target: self
                                   selector: @selector(simPressRed:)
                                   userInfo: nil
                                    repeats: NO];

以及更改图像的代码:

[btnRed setImage:[UIImage imageNamed:@"btn_red.png"] forState:UIControlStateNormal];

如果 tmpLvlSpeed 小于 1.0,则按钮图像将永远不会更改。即使 simPressRed 函数仍然会触发。

有什么线索吗?我可以修改更新周期吗?

I am currently working with the iPhone SDK.

I have a NSTimer that changes the background image of a UIButton.
Once this is complete, it will trigger the same action again (reset the NSTimer) for a predetermined number of times.

My problem is that if my NSTimer is set to execute more than once per second. (0.75, say) The background image wont change.

I am using NSLog to check that the event fires. But the button image will just remain in its original state.

Is there any way to change the background image more often than once per second?

This is my timer :

[NSTimer scheduledTimerWithTimeInterval: tmpLvlSpeed
                                     target: self
                                   selector: @selector(simPressRed:)
                                   userInfo: nil
                                    repeats: NO];

And the code to change the image:

[btnRed setImage:[UIImage imageNamed:@"btn_red.png"] forState:UIControlStateNormal];

if tmpLvlSpeed is less than 1.0, the button image will never change. Even though the simPressRed function will still fire.

Any clues? Is there an update cycle I can modify?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的味道 2024-09-03 07:47:55

您是否尝试过使用setNeedsDisplay

[button setNeedsDisplay];

Have you tried to use setNeedsDisplay?

[button setNeedsDisplay];
近箐 2024-09-03 07:47:55

你有多少张图片?从您提供给我们的内容来看,您只有一张图像,所以图像不会改变。请发布您的代码,以便我们进一步帮助您

how many images do you have? From what you gave us, you only have one image, so no duh the image won't change. Please post the code you have so we can further help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文