The iOS Disable button is clicked continuously for a certain period of time

  • 2021-11-01 05:00:00
  • OfStack

When writing a project, I encountered this embarrassing problem. Some of them need to make network requests, or some mobile phones are a little stuck, and users will click continuously. It often appears that two identical controllers of Push are connected, and of course there are methods of repeatedly calling network requests, and so on. . . .

The more stupid method is to turn off the user interaction at every click, and then resume the user interaction of this button after the function is realized.

Of course, this method can be achieved completely, but if the number is too much, it is necessary to write a lot of repeated code. Is there a simple method of 1 point? ? ?

Really, I wrote a static library to achieve this function.

This is the address of GitHub:

https://github.com/YouZhiZheShiJingCheng/YZ_button

That how to use, actually very simple, you just have to pull this folder directly into the project can.

Continuous clicking events of all buttons must wait for 1S. (It's as simple as that.)

Some people said that some buttons do not need to be limited, or the time limit can be set by themselves.

Of course, you only need to import it in PCH file

YZ_Button.h

In this way, you can modify the time, and of course you can cancel the time.

For example:

Change time


UIButton * btn = [[UIButton alloc] init];
btn.s = 1.5;

In this case, the continuous click events of buttons must be separated by 1.5 S

If you don't want to limit it, it is simple, just change the above 1.5 to 520

btn.s=520

In this way, there will be no restrictions on buttons


Related articles: