Lotus

Lotus – powerful nano framework that helps implement layer animation with easy syntax. This DSL relieves you from routine code of making animations via CoreAnimation.

Lotus

for i in 0..<10 {
    let petalLayer = PetalLayer()
    petalLayer.position = CGPoint(x: view.frame.width / 2, y: view.frame.height / 2 + 60)

    let direction: CGFloat = i % 2 == 0 ? -1.0 : 1.0
    let initialRotationDegree = 3.0 * CGFloat(i / 2) * .pi / 180.0
    let rotateTransform = CGAffineTransform.identity.rotated(by: direction * initialRotationDegree)
    petalLayer.setAffineTransform(rotateTransform)
    view.layer.addSublayer(petalLayer)

    let rotationDegree = 12.0 * CGFloat(i / 2) * .pi / 180.0
    petalLayer.lotus.runAnimation { make in
        make.opacity.to(0.7).during(0.7).delay(1.0)
    }.then { make in
        make.rotation.to(direction * rotationDegree).during(0.6)
    }.then { make in
        make.scaling.to(1.2).delay(0.3).during(1.5).ease(.outElastic)
    }
}

Getting started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Requirements

  • Xcode 10.2+
  • Cocoapods 1.7.0+
  • Git client

Installing

CocoaPods

  1. In terminal switch to your repository with project
  2. Specify Lotus in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Lotus'
end
  1. Run pod install command

Usage

  1. Import Lotus into your project
import Lotus
  1. Create any layer and add to view's hierarchy
let redSquareLayer = CALayer()
redSquareLayer.frame = CGRect(x: 50.0, y: 50.0, width: 100.0, height: 100.0)
view.layer.addSublayer(redSquareLayer)
  1. Then run any needed animation whenever you need
redSquareLayer.lotus.runAnimation { make in
    make.rotation.to(360.0 * .pi / 180.0).during(2.0)
}.then { make in
    make.scaling.to(2.2)
}.then { make in
    make.scaling.to(1.8)
}

GitHub