This is Swift library that creates animated objects that seem to flickering.
DYBlinkObject is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'DYBlinkObject'
DYBlinkObject was deployed as Swift Package Manager. Package to install in a project. Add as a dependent item within the swift manifest.
let package = Package(
...
dependencies: [
.package(url: "https://github.com/BluePepper-iOS/DYBlinkObject.git", from: "1.0.0")
],
...
)
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Import project Then import the DYBlinkObject from thr location you want to use.
import DYBlinkObject
- Instance
let blinkObject = DYBlinkObject()
- Make Object
let firstObject = blinkObject.drawObject(width: 200, height: 200)
- Add Animation
blinkObject.addBlinkingAnimation(to: firstObject, withDuration: 2.0, delay: 0.0, minAlpha: 0.5)
let firstObject = blinkObject.draw(width: 200, height: 200)
blinkObject.addBlinkingAnimation(to: firstObject, withDuration: 2.0, delay: 0.0, minAlpha: 0.5)
let secondObject = blinkObject.draw(width: 300, height: 40, radius: 10)
blinkObject.addBlinkingAnimation(to: secondObject, withDuration: 1.0, delay: 0.0, minAlpha: 0.2)
/**
Returns a UIView object with the specified size, corner radius, and background color, and adds a flickering animation to it.
- Parameters:
- width: The width of the view.
- height: The height of the view.
- radius: The corner radius of the view.
- Returns: A UIView object with the specified size, corner radius, and background color, and a flickering animation.
*/
public func draw(width: CGFloat, height: CGFloat, radius: CGFloat = 20, color: UIColor = .white) -> UIView {
let object = UIView()
object.translatesAutoresizingMaskIntoConstraints = false
object.backgroundColor = color
object.layer.cornerRadius = radius
object.clipsToBounds = true
object.widthAnchor.constraint(equalToConstant: width).isActive = true
object.heightAnchor.constraint(equalToConstant: height).isActive = true
return object
}
/**
Adds a blinking animation to the given `UIView` object.
- Parameters:
- object: The `UIView` object to which the blinking animation will be added.
- duration: The duration of the animation.
- delay: The delay before the animation starts.
- minAlpha: The minimum alpha value for the `UIView`.
- Note: This function uses the `UIView.animate(withDuration:delay:options:animations:)` method to create the blinking animation.
*/
public func addBlinkingAnimation(to object: UIView, withDuration duration: TimeInterval, delay: TimeInterval, minAlpha: CGFloat) {
UIView.animate(withDuration: duration, delay: delay, options: [.repeat, .autoreverse]) {
object.alpha = minAlpha
}
}
doyeonjeong, [email protected]
DYBlinkObject is available under the MIT license. See the LICENSE file for more info.