Pop – The dynamic change of any property of any iOS object

Source: Internet
Author: User

Brief introduction

Pop is an extensible animation engine that can be used to dynamically change any property of any iOS object, supporting three types of general animation, elastic animation, and gradient animation.

    • Project home: Pop
    • Latest example: Click to download
    • Note: The official code does not contain an instance, but all the source code used to compile it, it is recommended to create a new project on your own and see the effect in conjunction with the code snippet below.
Getting Started installs by Cocoapods
pod ‘pop‘, ‘~> 1.0‘
Use

In places where POPs are needed, the header file is introduced:

#import <pop/POP.h>
Start of animation, stop and update

You can start the animation by adding the animation to the object you want to change dynamically:

POPSpringAnimation *anim = [POPSpringAnimation animation];...[layer pop_addAnimation:anim forKey:@"myKey"];

You can remove the corresponding animation based on the key that was passed in when you started the animation:

[layer pop_removeAnimationForKey:@"myKey"];

The key that is passed in when the animation starts, and can also be used to query for the presence of an animation. Update the Tovalue of an ongoing animation to seamlessly achieve transitions between animation effects:

anim = [layer pop_animationForKey:@"myKey"];if (anim) {  /* 更新toValue为一个新值. */  anim.toValue = @(42.0);} else {  /* 创建并开始一个新的动画. */  ....}

The example above is the example of a layer. Pop is implemented in a nsobject way. That is, any nsobject and its subclasses can be animated by pop.

Type of animation

There are four types of animation: Elastic animation, fade animation, base animation, and custom animation.

Elastic animation

Elastic animations can give the object a vibrant bounce effect. In the following example, we use elastic 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 animations

A gradient animation that allows the object to slowly stop changing. In the following example, we make the horizontal axis of the layer gradient from the current value at a rate of 1000 pixels per second:

POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];anim.velocity = @(1000.);[layer pop_addAnimation:anim forKey:@"slide"];
Basic animations

The underlying animation can be used to dynamically change the value of a property over a specified period of time. Dynamically change the transparency of the view from 0.0 to 1.0来 in the default time period to achieve fade-in effects:

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 animations

POPCustomAnimationUse to create custom animations and transitions. It manages the association of time and animation by managing Cadisplaylink. For more details, see the header file.

Animation properties

Animation properties are POPAnimatableProperty managed by the class and are used to specify which property to apply the animation effect to. In the following example, we create an elastic animation and display the Set animation property to the -[CALayer bounds] corresponding property:

POPSpringAnimation *anim = [POPSpringAnimation animation];anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerBounds];

This framework loves to pre-implement many of the animation properties that are common to layers and views, and you can use them directly in your own projects. You can also POPAnimatableProperty create a custom animation property by creating an instance of the class. In the following example, we define a custom volume animation property:

prop = [POPAnimatableProperty propertyWithName:@"com.foo.radio.volume" initializer:^(POPMutableAnimatableProperty *prop) {  // 读取动画属性的值  prop.readBlock = ^(id obj, CGFloat values[]) {    values[0] = [obj volume];  };  // 设置动画属性的值.  prop.writeBlock = ^(id obj, const CGFloat values[]) {    [obj setVolume:values[0]];  };  // 力学上的临界值  prop.threshold = 0.01;}];anim.property = prop;

The predefined animation properties of the system are also defined by the mechanism of the above example, which is useful for reference when customizing animated properties. A complete list of predefined animated properties and their implementation details see POPAnimatableProperty.h :

/** Layer (Calayer) general animation properties. */extern NSString * Const kpoplayerbackgroundcolor;extern NSString * Const kpoplayerbounds;extern NSString * Const KPOPLAY Ercornerradius;extern NSString * Const kpoplayerborderwidth;extern NSString * Const Kpoplayerbordercolor;extern NSString * CONST Kpoplayeropacity;extern NSString * Const kpoplayerposition;extern NSString * Const KPOPLAYERPOSITIONX;EX Tern NSString * Const kpoplayerpositiony;extern NSString * Const kpoplayerrotation;extern NSString * Const Kpoplayerrotati Onx;extern NSString * Const kpoplayerrotationy;extern NSString * Const kpoplayerscalex;extern NSString * Const KPOPLAYERSC Alexy;extern NSString * Const kpoplayerscaley;extern NSString * Const kpoplayersize;extern NSString * Const KPOPLAYERSUBSC Alexy;extern NSString * Const kpoplayersubtranslationx;extern NSString * Const Kpoplayersubtranslationxy;extern NSString * CONST Kpoplayersubtranslationy;extern NSString * Const kpoplayersubtranslationz;extern NSString * Const KPOPLA Yertranslationx;externNSString * CONST Kpoplayertranslationxy;extern NSString * Const kpoplayertranslationy;extern NSString * Const KPOPLAYERTR Anslationz;extern NSString * Const kpoplayerzposition;extern NSString * Const Kpoplayershadowcolor;extern NSString * Cons T kpoplayershadowoffset;extern NSString * CONST kpoplayershadowopacity;extern NSString * Const kpoplayershadowradius;/*  * Graphics Layer (Cashapelayer) general animation properties. */extern NSString * Const kpopshapelayerstrokestart;extern NSString * Const kpopshapelayerstrokeend;extern NSString * Con  St Kpopshapelayerstrokecolor;extern NSString * const kpopshapelayerfillcolor;/** View constraint (nslayoutconstraint) Universal Animation properties. */extern NSString * Const kpoplayoutconstraintconstant;/** View (UIView) General animation properties. */extern NSString * Const kpopviewalpha;extern NSString * Const kpopviewbackgroundcolor;extern NSString * Const KPOPVIEWBO Unds;extern NSString * Const kpopviewcenter;extern NSString * Const kpopviewframe;extern NSString * Const KPOPVIEWSCALEX;E Xtern NSString * Const Kpopviewscalexy;extern NSString* Const Kpopviewscaley;extern NSString * Const kpopviewsize;extern NSString * Const kpopviewtintcolor;/** scrolling view (UIScrollVi EW) General animation properties. */extern NSString * Const kpopscrollviewcontentoffset;extern NSString * Const Kpopscrollviewcontentsize;extern NSString * Const Kpopscrollviewzoomscale;extern NSString * Const kpopscrollviewcontentinset;/** List (UITableView) General animation properties. */extern NSString * Const kpoptableviewcontentoffset;extern NSString * Const kpoptableviewcontentsize;/** Collection View ( Uicollectionview) General animation properties. */extern NSString * Const kpopcollectionviewcontentoffset;extern NSString * Const kpopcollectionviewcontentsize;/** navigation bar (Uinavigationbar) General animation properties. */extern NSString * Const kpopnavigationbarbartintcolor;/** Toolbar (Uitoolbar) General animation properties. */extern nsstring * Const kpoptoolbarbartintcolor;/** tab Bar (Uitabbar) General animation properties. */extern NSString * Const kpoptabbarbartintcolor;/** label (UILabel) Universal Animation properties. */extern NSString * Const Kpoplabeltextcolor;

Pop – dynamic changes to any property of any iOS object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.