iOS controls the trigger frequency of button click events

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.