Coder Social home page Coder Social logo

ldrr / uiview-animatedproperty Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tricertops/uiview-animatedproperty

0.0 2.0 0.0 196 KB

Extending `UIView` block animations to allow you to implement custom animated properties.

License: MIT License

Objective-C 100.00%

uiview-animatedproperty's Introduction

UIView+AnimatedProperty Flattr this

This extension to UIView block animations allows you to implement your own animated properties of UIView subclasses.

The main part is category on UIView that swizzles animation methods to extend them. Extended methods store duration, delay and options of the current animation to globally accessible variable (via accessor +currentAnimation). Then in setter of your animated property you check whether you are called in context of animation block and can alter the behavior (usually by running CAAnimation).

In addition, it supports nested animations with proper overriding of inherited duration and curve. Also it provides easy contructor for CABasicAnimation and accessors for animation options.

Example

Your UIView subclass with custom animated property:

@implementation ANPCornerView

@dynamic cornerRadius;

- (CGFloat)cornerRadius {
    return self.layer.cornerRadius;
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
    if ([UIView currentAnimation]) {
        [[UIView currentAnimation] animateLayer:self.layer keyPath:@"cornerRadius" toValue:@(cornerRadius)];
    }
    else {
        self.layer.cornerRadius = cornerRadius;
    }
}

This is how you use it:

[UIView animateWithDuration:5 animations:^{
    myView.cornerRadius = 50;
}];

For more detailed example, see the project.


Version 0.4.0

MIT License, Copyright © 2013 Martin Kiss

THE SOFTWARE IS PROVIDED "AS IS", and so on...

uiview-animatedproperty's People

Contributors

kenhama avatar tricertops avatar

Watchers

 avatar  avatar

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.