Tag: iOS controls the trigger frequency of the button click event
This is often a problem in projects:
A button click triggers the corresponding click event, such as sending a network request to the server or popping a popup box.
But if the user clicks the frequency quickly, it will not stop triggering the Click event, thus causing the UI to go awry.
My solution to this problem is to set a Boolean value.
(1) For click events that interact with the server: determine the bool value when clicked, set one time before sending the request, and change the bool value after the server has been answered.
(2) for server-free interactive Click event: Click on the time to judge, the execution of the frame before the box, the frame after the delay of 0.25 seconds in the setting.
Directly on the code
....
@property (nonatomic,assign) BOOL hasliked;
....
-(void) viewwillappear: ( BOOL ) Animated
{
[superviewwillappear: animated];
self. hasliked = YES ;
}
-(void) Btnclick: ( UIButton *) button
{
__weak vswiperviewcontroller *weakself = self;
if (button. Tag == - ) {
nsinteger useraccountscore = [[vuserinfoentitymanager Sharedmanager] getprivateuserinfo]. score ;
if (Useraccountscore <_fpzgiftprice &&self. /c7>hasliked = =YES) { // Click to Judge hasliked
self. hasliked = NO ;//Perform a bullet box before setting
[weakself shownotenoughcoinsalertview];
dispatch_after(dispatch_time(dispatch_time_now, (int64_t) (0.25 * nsec_per_sec)), Dispatch _get_main_queue(), ^{
weakself. hasliked = YES after the frame is finished, the 0.25-second delay is set
});
}
}
iOS controls the trigger frequency of button click events