Introduction
Welcome to the documentation for DJRepeatClickFilter, a library that prevents repeated clicks on the iOS platform. This library provides an easy-to-use solution for handling multiple unintentional clicks and ensures that actions are triggered only once, improving the user experience.
Features
- Preventing duplicated actions: DJRepeatClickFilter prevents duplicated actions caused by multiple rapid clicks on buttons or views.
- Easy integration: Simply add a few lines of code to your existing project to enable the click filtering functionality.
- Customizable: Various configuration options allow you to adapt DJRepeatClickFilter to your specific needs.
Requirements
In order to use DJRepeatClickFilter, your project needs to meet the following requirements:
- iOS 9.0 or above
- Xcode 11 or above
- Swift 5.0 or above
Installation
To install DJRepeatClickFilter using CocoaPods, add the following line to your Podfile
:
// Podfile
pod 'DJRepeatClickFilter'
Then, run the command pod install
in your Terminal.
Quick Start
- Import DJRepeatClickFilter in your view controller:
- Add DJRepeatClickFilterDelegate to your view controller:
- Create an instance of DJRepeatClickFilter:
- Enable DJRepeatClickFilter for your desired button:
- Implement the DJRepeatClickFilterDelegate method to handle the single click event:
- Finally, don’t forget to set the delegate for DJRepeatClickFilter:
// ViewController.swift
import DJRepeatClickFilter
// ViewController.swift
class ViewController: UIViewController, DJRepeatClickFilterDelegate {
// ViewController.swift
let clickFilter = DJRepeatClickFilter()
// ViewController.swift
clickFilter.enableFilter(for: myButton)
// ViewController.swift
func didClickOn(_ view: UIView) {
// Handle the single click event
}
// ViewController.swift
clickFilter.delegate = self
Configuration
DJRepeatClickFilter provides various options for customization. Use these methods to configure DJRepeatClickFilter according to your requirements:
setInterval:
Define the allowed interval (in seconds) between clicks. Default is 0.5 seconds.setClickCount:
Specify the number of accumulated clicks required to trigger the action. Default is 1.resetClickCountAfterInterval:
Set whether the accumulated click count should be reset after the specified interval. Default istrue
.setMultipleClickAction:
Define the action to be taken when multiple clicks are detected. Default action is to do nothing.setUnfilteredAction:
Set the action to be performed when clicks are not filtered. Default action is to do nothing.
Example usage:
// ViewController.swift
clickFilter.setInterval(1.0) // Allow clicks every 1 second
clickFilter.setClickCount(2) // Trigger action after 2 clicks
clickFilter.resetClickCountAfterInterval(false) // Keep accumulated clicks until manually reset
clickFilter.setMultipleClickAction {
// Handle multiple clicks
}
clickFilter.setUnfilteredAction {
// Handle unfiltered clicks
}
Conclusion
By implementing DJRepeatClickFilter in your iOS project, you can prevent repeated clicks and provide a smoother user experience. Enjoy using DJRepeatClickFilter, and feel free to customize it to fit your specific needs!