Giter Club home page Giter Club logo

layerkit's Introduction

LayerKit

Have fun with CALayers!

Example

let bounds = view.bounds

let width: CGFloat = bounds.width - 32
let height: CGFloat = bounds.height - 32
let x: CGFloat = 16
let y: CGFloat = 16

view.layer
    .background(color: UIColor.cyan.cgColor)
    .embed {
        Layer(backgroundColor: UIColor.red.cgColor)
            .frame(x: x, y: y, width: width, height: height)
            .corner(radius: 32)
            .masked(corners: [.layerMaxXMaxYCorner, .layerMaxXMinYCorner])
            .embed {
                Layer(backgroundColor: UIColor.gray.cgColor)
                    .frame(x: 50, y: 400, width: 100, height: 30)
                    .corner(radius: 16)
            }
    }

layerkit's People

Contributors

0xleif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

layerkit's Issues

Implement Basic Delegate

CALayerDelegate

CALayer.delegate

You can use a delegate object to provide the layer’s contents, handle the layout of any sublayers, and provide custom actions in response to layer-related changes. The object you assign to this property should implement one or more of the methods of the CALayerDelegate informal protocol. For more information about that protocol, see CALayerDelegate
In iOS, if the layer is associated with a UIView object, this property must be set to the view that owns the layer.

Implement Layout

var layoutManager: CALayoutManager?
The object responsible for laying out the layer’s sublayers.

func setNeedsLayout()
Invalidates the layer’s layout and marks it as needing an update.

func layoutSublayers()
Tells the layer to update its layout.

func layoutIfNeeded()
Recalculate the receiver’s layout, if required.

func needsLayout() -> Bool
Returns a Boolean indicating whether the layer has been marked as needing a layout update.

var autoresizingMask: CAAutoresizingMask
A bitmask defining how the layer is resized when the bounds of its superlayer changes.

func resize(withOldSuperlayerSize: CGSize)
Informs the receiver that the size of its superlayer changed.

func resizeSublayers(withOldSize: CGSize)
Informs the receiver’s sublayers that the receiver’s size has changed.

func preferredFrameSize() -> CGSize
Returns the preferred size of the layer in the coordinate space of its superlayer.

Implement CATiledLayer

CATiledLayer

A layer that provides a way to asynchronously provide tiles of the layer's content, potentially cached at multiple levels of detail.

Implement Content Image

var contents: Any?
An object that provides the contents of the layer. Animatable.

var contentsRect: CGRect
The rectangle, in the unit coordinate space, that defines the portion of the layer’s contents that should be used. Animatable.

var contentsCenter: CGRect
The rectangle that defines how the layer contents are scaled if the layer’s contents are resized. Animatable.

func display()
Reloads the content of this layer.

func draw(in: CGContext)
Draws the layer’s content using the specified graphics context.

About Core Animation

Core Animation Programming Guide

You may never need to use Core Animation directly, but when you do you should understand the role that Core Animation plays as part of your app’s infrastructure.

Data Types

Core Animation is a graphics rendering and animation infrastructure available on both iOS and OS X that you use to animate the views and other visual elements of your app. With Core Animation, most of the work required to draw each frame of an animation is done for you. All you have to do is configure a few animation parameters (such as the start and end points) and tell Core Animation to start. Core Animation does the rest, handing most of the actual drawing work off to the onboard graphics hardware to accelerate the rendering. This automatic graphics acceleration results in high frame rates and smooth animations without burdening the CPU and slowing down your app.

If you are writing iOS apps, you are using Core Animation whether you know it or not. And if you are writing OS X apps, you can take advantage of Core Animation with extremely little effort. Core Animation sits beneath AppKit and UIKit and is integrated tightly into the view workflows of Cocoa and Cocoa Touch. Of course, Core Animation also has interfaces that extend the capabilities exposed by your app’s views and give you more fine-grained control over your app’s animations.

Implement Constraints

var constraints: [CAConstraint]?
The constraints used to position current layer’s sublayers.

func addConstraint(CAConstraint)
Adds the specified constraint to the layer.

Implement ScrollLayer

CAScrollLayer

var visibleRect: CGRect
The visible region of the layer in its own coordinate space.

func scroll(CGPoint)
Initiates a scroll in the layer’s closest ancestor scroll layer so that the specified point lies at the origin of the scroll layer.

func scrollRectToVisible(CGRect)
Initiates a scroll in the layer’s closest ancestor scroll layer so that the specified rectangle becomes visible.

Implement Actions

CAAction

func action(forKey: String) -> CAAction?
Returns the action object assigned to the specified key.

var actions: [String : CAAction]?
A dictionary containing layer actions.

Action Identifiers
These constants are the predefined action identifiers used by action(forKey:), add(_:forKey:), defaultAction(forKey:), removeAnimation(forKey:), Layer Filters, and the CAAction protocol method run(forKey:object:arguments:).

Implement Animations

func add(CAAnimation, forKey: String?)
Add the specified animation object to the layer’s render tree.

func animation(forKey: String) -> CAAnimation?
Returns the animation object with the specified identifier.

func removeAllAnimations()
Remove all animations attached to the layer.

func removeAnimation(forKey: String)
Remove the animation object with the specified key.

func animationKeys() -> [String]?
Returns an array of strings that identify the animations currently attached to the layer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.