Waiting for UIButton to revert to UIControlStateNormal

蓝咒 提交于 2019-12-13 02:55:17

问题


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

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

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 I would rather avoid using some arbitrary timer to wait a set interval.


回答1:


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.

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

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

with the control event set to UIControlEventTouchUpInside



来源:https://stackoverflow.com/questions/12149687/waiting-for-uibutton-to-revert-to-uicontrolstatenormal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!