问题
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