每秒多次更改 UIButton 背景图像
我目前正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用
setNeedsDisplay
?Have you tried to use
setNeedsDisplay
?你有多少张图片?从您提供给我们的内容来看,您只有一张图像,所以图像不会改变。请发布您的代码,以便我们进一步帮助您
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