Giter VIP home page Giter VIP logo

iosanimation's People

Contributors

kieuquangloc avatar

Stargazers

 avatar

Watchers

 avatar

iosanimation's Issues

Understanding Animation


Core Animation (Layer Animations)

  • 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.

  • 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. 

  • Core Animation is not executed on the CPU. Their commands are more offloaded to the GPU and used to create the graphics that are shown on the screen, powered by the GPU hardware.

    image

 1. CAAnimation
CAAnimation provides the basic support for the CAMediaTiming and CAAction protocols. You do not create instance of CAAnimation: to animate Core Animation layers or SceneKit objects, create instances of the concrete subclasses CABasicAnimation, CAKeyframeAnimation, CAAnimationGroup, or CATransition.




image

a. CAPropertyAnimation:

* An abstract subclass of CAAnimation for creating animations that manipulate the value of layer properties.

  • You do not create instances of CAPropertyAnimation: to animate the properties of a Core Animation layer, create instance of the concrete subclasses CABasicAnimation or CAKeyframeAnimation.

b. CABasicAnimation:

c. CAKeyframeAnimation:

image

2. Animation Groups 
a. CAAnimationGroup:

* An object that allows multiple animations to be grouped and run concurrently.
* If you want to apply multiple animations to a layer object simultaneously, you can group them together using a CAAnimationGroup object. Using a group object simplifies the management of multiple animation objects by providing a single configuration point. Timing and duration values applied to the group override those same values in the individual animation objects. For example below the link: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/CreatingBasicAnimations/CreatingBasicAnimations.html

b. CATransaction

* CATransaction is the Core Animation mechanism for batching multiple layer-tree operations into atomic updates to the render tree. Every modification to a layer tree must be part of a transaction. Nested transactions are supported.
* Advanced CATransition Tricks : https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/TP40004514-CH8-SW1

**   3. Animation time**

Layer Basics

1. CALayer

  • An object that manages image-based content and allows you to perform animations on that content.
  • A layer’s main job is to manage the visual content that you provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow. In addition to managing visual content, the layer also maintains information about the geometry of its content (such as its position, size, and transform) that is used to present that content onscreen. More detail about CALayer : https://gist.github.com/JeOam/94e833bcefd738d805cc

  • Core Animation defines many standard layer classes, each of which was designed for a specific use case. The CALayer class is the root class for all layer objects. It defines the behavior that all layer objects must support and is the default type used by layer-backed views.



image

**   2. CALayerDeleagte**

▪ You can implement the methods of this protocol to provide the layer’s content, handle the layout of sublayers, and provide custom animation actions to perform. The object that implements this protocol must be assigned to the delegate property of the layer object.


  • If the layer object was created by a view, the view typically assigns itself as the layer’s delegate automatically, and you should not change that relationship. For layers you create yourself, you can assign a delegate object and use that object to provide the contents of the layer dynamically and perform other task.


 3. CAConstraint

  • A representation of a single layout constraint between two layers.

  • It is possible to create constraints that result in circular references to the same attributes. In cases where the layout is unable to be computed the behavior is undefined.


 4. CAAction

  • An interface that allows objects to respond to actions triggered by a CALayer change. 



  • CAAction protocol
Action is an object that can respond to events
CAAnimation implements CAActionProtocol
Action (if found) added using [self addAnimation: forKey :]


image

5. CALayoutManager

▪ Methods that allow an object to manage the layout of a layer and its sublayers.


6. CAConstraintLayoutManager
• An object that provides a constraint-based layout manager.



 7. CATransform 
Every layer has two transform matrices that you can to manipulate the layer.

View Animations

1. AnimationWithBlocks (UIViewAnimationWithBlocks)

  • In iOS 4, UIView introduced some new methods which we can use that use blocks : https://developer.apple.com/documentation/uikit/uiview?changes=_4&language=objc
  • There are two premade blocks that can be used to play the required animation (transparency, position and size change): animations and completion. They have different uses:
  • In the Animations block the code is executed during the animation.
    • In the Completion block the code is executed after the Animations block is completed.

2. AnimateKeyframes (UIViewKeyframeAnimations)

  • In iOS 7 Apple introduced a new animation method named animateKeyframes. Video WWDC: https://developer.apple.com/videos/play/wwdc2013/218/
  • The animation methods in UIView have allowed animation of animatable properties (such as transform, backgroundColor,frame, center etc) – by setting an end-state, duration and other options such as animation curve. However, setting intermediate states in the animation, so-called key-frames, has not been possible. In this case it was necessary to drop down to CoreAnimation itself and create a CAKeyFrameAnimation. This changes in iOS7 – with the addition of 2 methods to UIView, the first of which is similar to the other block-based animation methods: animateKeyframesWithDuration:delay:options:animations:completion:. This takes floats for duration and delay, a bit-mask for options and blocks for animation and completion – all pretty standard in the world of UIView animations. The difference comes in the method we call inside the animation block: addKeyframeWithRelativeStartTime:relativeDuration:animations:. This method is used to add the fixed points within the animation sequence. More detail: https://www.shinobicontrols.com/blog/ios7-day-by-day-day-11-uiview-key-frame-animations


3. Animations with UIViewPropertyAnimator

  • Introduced in iOS 10, helps developers create interactive, interruptible view animations: https://developer.apple.com/videos/play/wwdc2016/216/.

  • In iOS 10 Use animationblocks methods is discouraged (?). Use the UIViewPropertyAnimator class to perform animations instead.

    image

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.