Using pop animations to write custom animation effects with rich text

Source: Internet
Author: User

Using pop animations to write custom animation effects with rich text

Source

Https://github.com/YouXianMing/POPNumberCount

Effect

Characteristics

* Support Rich Text

* Customizable Strong (inheriting parent class overriding the Startanimation method of the parent class)

* Support for animation interrupts and persistence

* Support camediatimingfunction

* Data is isolated from the UI so you could encapsulate your class

Core

////POPNumberCount.h//POP////Created by Xianmingyou on 15/4/10.//Copyright (c) 2015 xianmingyou. All rights reserved.//#import<Foundation/Foundation.h>#import "POP.h"@classPopnumbercount;@protocolPopnumbercountdelegate <NSObject>@optional/** the most primitive method * * @param numbercount object itself * @param number Change value*/- (void) Numbercount: (Popnumbercount *) Numbercount currentnumber: (NSNumber *) number;/** * Subclasses can implement the method * * @param numbercount object itself * @param Rich text returned by the string subclass*/- (void) Numbercount: (Popnumbercount *) Numbercount currentattributedstring: (nsattributedstring *)string;/** * Subclasses can implement the method * * @param numbercount The object itself * @param the text returned by the string subclass*/- (void) Numbercount: (Popnumbercount *) Numbercount currentstring: (NSString *)string;@end@interfacePopnumbercount:nsobject@property (nonatomic, weak)ID<POPNumberCountDelegate>Delegate;//Agent@property (nonatomic, assign) CGFloat fromvalue; //Start Value@property (nonatomic, assign) CGFloat tovalue;//End Value@property (nonatomic, assign) CGFloat CurrentValue;//Current Value@property (nonatomic, assign) nstimeinterval duration;//Duration@property (nonatomic, strong) Camediatimingfunction*timingfunction;//Time Function@property (nonatomic, strong) Popbasicanimation *conutanimation;/** Store VALUES (store the values you set before performing the animation)*/- (void) savevalues;/** Start Animation (inherited subclasses need to override this method and then work with the agent)*/- (void) startanimation;/** Stop Animation*/- (void) stopanimation;@end
////POPNUMBERCOUNT.M//POP////Created by Xianmingyou on 15/4/10.//Copyright (c) 2015 xianmingyou. All rights reserved.//#import "POPNumberCount.h"#import "ConfigAttributedString.h"@implementationPopnumbercount-(instancetype) init { self=[Super Init]; if(self) {self.conutanimation=[popbasicanimation animation]; }    returnSelf ;}- (void) savevalues {self.conutAnimation.fromValue=@ (Self.fromvalue); Self.conutAnimation.toValue=@ (Self.tovalue); Self.conutAnimation.duration= (Self.duration <=0?0.4f: self.duration); if(self.timingfunction) {self.conutAnimation.timingFunction=self.timingfunction; }}- (void) startanimation {//The Count engine executes only if the agent is executed    if(self.)Delegate&& [Self.Delegaterespondstoselector: @selector (numbercount:currentnumber:)]) {        /*set the calculated value dynamically to the control by WriteBlock*/Self.conutAnimation.property=[Popmutableanimatableproperty propertywithname:@"conutanimation"initializer:^ (Popmutableanimatableproperty *prop) {Prop.writeblock= ^(IDObjConstCGFloat values[]) {NSNumber*number = @ (values[0]); _currentvalue= values[0]; /*-------------Subclass overrides this method of the parent class-------------*/[_delegate numbercount:self Currentnumber:number]; /* ---------------------------------------------- */                                               };                }]; //Add animations[self pop_addAnimation:self.conutAnimation forkey:nil]; }}- (void) stopanimation {[Self pop_removeallanimations];}@end

Description

The parent class Popnumbercount is designed to resemble a policy pattern in design mode, providing an interface for subclasses to override to implement a different function, and the parent class will not be modified to a subclass, only the specific implementation in the subclass needs to be modified. (A protocol in the parent class is similar to a policy, implemented by a subclass)

Using pop animations to write custom animation effects with rich text

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.