簡易的な連打防止に。
@interface UIControl (AfterDelay)
- (void)setEnabled:(BOOL)enabled afterDelay:(NSTimeInterval)delay;
@end
@implementation
- (void)setEnabled:(BOOL)enabled afterDelay:(NSTimeInterval)delay
{
int64_t delayInMilliSeconds = delay * 1000;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInMilliSeconds * NSEC_PER_MSEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self setEnabled:enabled];
});
}
@end
- (void)buttonAction:(UIButton *)button
{
[button setEnabled:NO];
[button setEnabled:YES afterDelay:0.8];
}