Pop-implement dynamic changes to any attributes of any iOS object, popios
Introduction
Pop is an extensible animation engine that can be used to dynamically change any attributes of any iOS object. It supports three types: General animation, elastic animation, and gradient animation.
Project homepage: pop
Latest example: Click to download
Note: The official code does not contain instances, but is used to compile all source code. We recommend that you create a new project and view the effect based on the code snippets below.
Get started with CocoaPods
pod 'pop', '~> 1.0'
Use
To use POP, introduce the header file:
#import <pop/POP.h>
Animation start, stop, and update
Add the animation to the object you want to have dynamic changes to start the animation:
POPSpringAnimation *anim = [POPSpringAnimation animation];...[layer pop_addAnimation:anim forKey:@"myKey"];
You can remove the corresponding animation based on the key entered during the animation start:
[layer pop_removeAnimationForKey:@"myKey"];
The key that is introduced when an animation starts. It can also be used to query whether an animation exists. Updating the toValue of an animation in progress can seamlessly transition between animation effects:
Anim = [layer pop_animationForKey: @ "myKey"]; if (anim) {/* update toValue to a new value. */anim. toValue = @ (42.0);} else {/* Create and start a new animation. */....}
The above example uses layers as an example. Pop is implemented through NSObject extension. That is to say, any NSObject and its subclass can add animation effects through Pop.
Animation type
There are four types of Animation: elastic animation, gradient animation, basic animation and Custom Animation.
Elastic Animation
Elastic animation can give objects a dynamic bounce effect. in the following example, we use an auto animation to change the Border Value of a layer from its current value to (0, 0,400,400 ):
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 400, 400)];[layer pop_addAnimation:anim forKey:@"size"];
Gradient Animation
Gradient animation allows the object to stop changing slowly. In the following example, we make the horizontal coordinates of the layer gradient from the current value at a speed of 1000 pixels per second:
POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];anim.velocity = @(1000.);[layer pop_addAnimation:anim forKey:@"slide"];
Basic Animation
The basic animation can be used to dynamically change the attribute value within a specified period of time. By default, the transparency of the view changes from 0.0 to 1.0 dynamically to fade-in effect:
POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];anim.fromValue = @(0.0);anim.toValue = @(1.0);[view pop_addAnimation:anim forKey:@"fade"];
Custom Animation
POPCustomAnimation
It is used to create custom animations and transition effects. It manages the relevance between time and animation by managing CADisplayLink. For more details, see the header file.
Animation attributes
Animation attributesPOPAnimatableProperty
Class Management is used to specify the attribute on which the animation effect is applied. In the following example, an elastic animation is created and the animation attribute is set-[CALayer bounds]
Corresponding attributes:
POPSpringAnimation *anim = [POPSpringAnimation animation];anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerBounds];
This framework is designed to implement many animation attributes shared by layers and views in advance. You can use them directly in your own projects. You can also createPOPAnimatableProperty
Class to create a Custom Animation attribute. In the following example, we define a custom volume animation attribute:
Prop = [POPAnimatableProperty propertyWithName: @ "com. foo. radio. volume "initializer: ^ (POPMutableAnimatableProperty * prop) {// read the animation attribute value prop. readBlock = ^ (id obj, CGFloat values []) {values [0] = [obj volume] ;}; // set the animation attribute value. prop. writeBlock = ^ (id obj, const CGFloat values []) {[obj setVolume: values [0] ;}; // mechanical critical value prop. threshold = 0.01;}]; anim. property = prop;
The predefined animation attributes of the system are also defined by the Mechanism in the preceding example. It is of great reference for customizing animation attributes. For a complete list of predefined animation attributes and their implementation details, seePOPAnimatableProperty.h
:
/** Layer (CALayer) Common animation attributes. */extern NSString * const alert; extern NSString * const kPOPLayerCornerRadius; extern NSString * const alert; extern NSString * const kPOPLayerBorderColor; extern NSString * const alert; extern NSString * const kPOPLayerPosition; extern NSString * const kPOPLayerPositionX; extern NSString * const condition; extern NSString * const kPOPLayerRotation; extern NSString * const condition; extern NSString * const kPOPLayerScaleX; extern NSString * const limit; extern NSString * const kPOPLayerScaleY; extern NSString * const kPOPLayerSize; extern NSString * const limit; extern NSString * const reverse; extern NSString * const kPOPLayerTranslationXY; extern NSString * const kPOPLayerTranslationY; extern NSString * const kPOPLayerTranslationZ; extern NSString * const kPOPLayerZPosition; extern NSString * const limit; /** graphic layer (CAShapeLayer) General animation attributes. */extern NSString * const kPOPShapeLayerStrokeStart; extern NSString * const constraint;/** view constraint (NSLayoutConstraint) Common animation attributes. */extern NSString * const kPOPLayoutConstraintConstant;/** view (UIView) Common animation attributes. */extern NSString * const alert; extern NSString * const kPOPViewCenter; extern NSString * const kPOPViewFrame; extern NSString * const kPOPViewScaleX; extern NSString * const trim; extern NSString * const kPOPViewScaleY; extern NSString * const kPOPViewSize; extern NSString * const kPOPViewTintColor;/** scroll view (UIScrollView) Common animation attributes. */extern NSString * const attributes; extern NSString * const kPOPScrollViewContentSize; extern NSString * const attributes; extern NSString * const kPOPScrollViewContentInset;/* List (UITableView) Common animation attributes. */extern NSString * const kPOPTableViewContentOffset; extern NSString * const kPOPTableViewContentSize;/** set view (UICollectionView) Common animation attributes. */extern NSString * const kPOPCollectionViewContentOffset; extern NSString * const kPOPCollectionViewContentSize;/** General animation attributes in the navigation bar (UINavigationBar. */extern NSString * const kpopnavigationbartintcolor;/** toolbar (UIToolBar) Common animation attributes. */extern NSString * const kpoptoolbartintcolor;/** tag bar (UITabBar) Common animation attributes. */extern NSString * const kpoptabbartintcolor;/** tag (UILabel) Common animation attributes. */extern NSString * const kPOPLabelTextColor;