Anim is a library that provides a convenient way to use animations in UIKit and create custom animations.
- iOS 11.0+ / tvOS 11.0+ / macOS 10.13+ / watchOS 7.0+
- Swift 5.0+
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate Anim
into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/GSM-MSG/Anim.git", .upToNextMajor(from: "1.0.0"))
]
If you prefer not to use either of the aforementioned dependency managers, you can integrate Miniature into your project manually.
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-16.at.13.11.55.mp4
import Anim
import UIKit
final class ViewController: UIViewController {
@IBOutlet weak var targetView: UIView!
@IBAction func fadeOutButtonDidTap(_ sender: Any) {
targetView.anim(anim: .fadeOut())
}
@IBAction func shake(_ sender: Any) {
targetView.anim(anim: .shake())
}
}
Anim
Protocol
The Anim protocol defines a contract for animations. It includes a single method animate(view:completion:), which is responsible for performing the animation on a given view.
Change the alpha value of the View to 0.
view.anim(anim: FadeOutAnim())
view.anim(anim: .fadeOut())
Change the alpha value of the View to 1.
view.anim(anim: FadeInAnim())
view.anim(anim: .fadeIn())
Change the alpha value of the View to 0 and 1.
view.anim(anim: FlashAnim())
view.anim(anim: .flash())
Change the alpha value of the View to argument value.
view.anim(anim: OpacityAnim(opacity: 0.5))
view.anim(anim: .opacity(opacity: 0.5))
Shake the View.
view.anim(anim: ShakeAnim())
view.anim(anim: .shake())
Rotate the View.
view.anim(anim: RotateAnim(angle: 1.3))
view.anim(anim: .rotate(angle: 1.3))
view.anim(anim: .rotate(angle: 1.3, reversed: true))
Moves the View in the direction of the argument by the argument offset value.
view.anim(anim: MoveFromAnim(direction: .top, offset: 100))
view.anim(anim: .moveFrom(direction: .top, offset: 100))
view.anim(anim: .moveFrom(direction: .top, offset: 100, reversed: true))
view.anim(anim: .moveFromTop(offset: 100))
view.anim(anim: .moveFromLeft(offset: 100))
view.anim(anim: .moveFromBottom(offset: 100))
view.anim(anim: .moveFromRight(offset: 100))
Scales the View by the argument value.
view.anim(anim: ScaleAnim())
view.anim(anim: .scale(scale: 1.5))
view.anim(anim: .scale(scale: 1.5, reversed: true))
Sleeps the View for the argument value.
view.anim(anim: SleepAnim())
view.anim(anim: .sleep(1.0))
Identity the View.
view.anim(anim: IdentityAnim())
view.anim(anim: .identity())
Serially executes the argument Animations.
view.anim(anim: SerialAnim(animations: [.fadeOut(), .sleep(1.0), .fadeIn()]))
view.anim(anim: .serial([.fadeOut(), .sleep(1.0), .fadeIn()]))
Concurrently executes the argument Animations.
view.anim(anim: ConcurrentAnim(animations: [.fadeOut(), .sleep(1.0), .fadeIn()]))
view.anim(anim: .concurrent([.fadeOut(), .sleep(1.0), .fadeIn()]))
You can create a custom Anim by implementing the Anim protocol.
struct CustomAnim: Anim {
func animate(view: UIView, completion: @escaping () -> Void) {
// Animation code
completion()
}
}
extension Anim where Self == CustomAnim {
static func custom() -> CustomAnim {
return CustomAnim()
}
}
view.anim(anim: CustomAnim())
view.anim(anim: .custom())
You can create custom CAAnimation by TransactionAnim execute.
struct CustomAnim: Anim {
func animate(view: UIView, completion: @escaping () -> Void) {
view.anim(anim: TransactionAnim {
// implemantation CAAnimation
return caanimation
})
}
}