31
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ボタンを一時的に無効化する

Posted at

簡易的な連打防止に。


@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];
}
31
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?