等待 UIButton 恢复为 UIControlStateNormal [英] Waiting for UIButton to revert to UIControlStateNormal

查看:19
本文介绍了等待 UIButton 恢复为 UIControlStateNormal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击我界面上的按钮时,我想使用 renderInContext 创建屏幕图像:

When a user taps a button on my interface, I want to create an image of the screen using renderInContext:

但是,图像是在按钮处于按下"状态时创建的 - 即使用 UIControlStateHighlighted 图像.

However, the image is created with the button in it's 'pressed' state - that is, the UIControlStateHighlighted image is used.

有没有办法在我创建图像之前等待这个按钮恢复到 UIControlStateNormal 状态?

Is there some way to wait for this button to revert back to the UIControlStateNormal state before I create the image?

如果没有,我能想到的唯一其他解决方案是重新创建屏幕外的视图,并对其进行成像.

If not, the only other solution I can think of is recreating the view off screen, and imaging that.

P.S 我宁愿避免使用任意定时器来等待设定的时间间隔.

P.S I would rather avoid using some arbitrary timer to wait a set interval.

推荐答案

用子类按钮创建和替换你的按钮,并在

Create and replace your button with a subclassed button and trigger your renderInContext when the

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event 

方法被调用.当用户将手指从按钮上移开时调用此方法.

method is called. This method is called when the user lifts their finger off the button.

或者使用uibutton的这个方法设置一个已有按钮的action方法:

Or set an action method of the existing button using this method of uibutton:

-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

控件事件设置为 UIControlEventTouchUpInside

with the control event set to UIControlEventTouchUpInside

这篇关于等待 UIButton 恢复为 UIControlStateNormal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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