Skip to content

Swift library that creates animated objects that seem to flickering.

License

Notifications You must be signed in to change notification settings

BluePepper-iOS/DYBlinkObject

Repository files navigation

DYBlinkObject

CI Status Version License Platform

Simulator Screen Recording - iPhone 14 Pro - 2023-03-10 at 19 12 04

Description

This is Swift library that creates animated objects that seem to flickering.

Installation

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")
    ],
    ...
)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

  1. Import project Then import the DYBlinkObject from thr location you want to use.
import DYBlinkObject
  1. Instance
let blinkObject = DYBlinkObject()
  1. Make Object
let firstObject = blinkObject.drawObject(width: 200, height: 200)
  1. Add Animation
blinkObject.addBlinkingAnimation(to: firstObject, withDuration: 2.0, delay: 0.0, minAlpha: 0.5)

Sample

Code Sample 1

let firstObject = blinkObject.draw(width: 200, height: 200)
blinkObject.addBlinkingAnimation(to: firstObject, withDuration: 2.0, delay: 0.0, minAlpha: 0.5)

Code Sample 2

let secondObject = blinkObject.draw(width: 300, height: 40, radius: 10)
blinkObject.addBlinkingAnimation(to: secondObject, withDuration: 1.0, delay: 0.0, minAlpha: 0.2)

Code: Drawing Object

/**
 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
}

Code: Add a flickering animation to the 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
    }
}

Author

doyeonjeong, [email protected]

License

DYBlinkObject is available under the MIT license. See the LICENSE file for more info.

About

Swift library that creates animated objects that seem to flickering.

Resources

License

Stars

Watchers

Forks

Packages

No packages published