Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhaoxiaobao/96f2c89ced46a7e57e363f25f8d6a840 to your computer and use it in GitHub Desktop.
Save zhaoxiaobao/96f2c89ced46a7e57e363f25f8d6a840 to your computer and use it in GitHub Desktop.
UIButton - 避免多次重复点击
#import <UIKit/UIKit.h>
@interface UIButton (antiMultiplyTouch)
- (void)antiMultiplyTouch:(NSTimeInterval)delay block:(void(^)(void))operation;
@end
== .m文件
#import "UIButton+AntiMultiplyTouch.h"
@implementation UIButton (AntiMultiplyTouch)
- (void)antiMultiplyTouch:(NSTimeInterval)delay block:(void(^)(void))operation
{
self.userInteractionEnabled = NO;
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
delay * NSEC_PER_SEC
),
dispatch_get_main_queue(),
^{
self.userInteractionEnabled = YES;
operation();
}
);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment