Let's see how some simple pop animations work.
//Add our red ball to the interfaceUIView*redball= [[UIView alloc] Initwithframe:cgrectmake ( -, -, the, the)];redball.backgroundcolor = [Uicolor Redcolor];redball.layer.cornerradius = the/2;//Half the width[Self.windowAddsubview:redball]; Popspringanimation*scale= [Popspringanimation animationwithpropertynamed:kpopviewscalexy]; Scale. Tovalue = [Nsvalue valuewithcgpoint:cgpointmake (2,2)]; Scale. springbounciness =20.0F//Between 0-20 Scale. Springspeed =1.0F//Between 0-20[RedBall pop_addanimation: ScaleForkey:@" Scale"];
This is the animation generated by this code.
Very resilient! We've talked a lot about how to create spring animations with jnwspringanimation and core animation, and now look at pop methods.
popspringanimation *scale = [Popspringanimation animationwithpropertynamed:kpopviewscalexy]; scale . Tovalue = [Nsvalue valuewithcgpoint:cgpointmake ( 2 , 2 )]; scale . springbounciness = 20.0 F; //between 0-20 scale . Springspeed = 1.0 F; //between 0-20 [RedBall pop_addanimation:scale forkey:@ " Scaleanimation
First, we created a new Popspringanimation object. It is designed with +animationwithpropertynamed: method to initialize, get parameters to tell pops what properties you want to animate. This is very much like the key path value we added in Jnwspringanimation, but not a simple string, pop designed a lot of values so you don't have to memorize strings. Here is a small number of pop properties that can be animated at any time.
- kpopviewalpha--the transparency of the view
- The overall frame of the kpopviewframe--view
- kpopviewscalexy--Stretching of Views (x and Y axes)
- kpopviewbackgroundcolor--the background color of the view
- The degree of Kpoplayercornerradius--layer's horn
- Kpoplayerrotation--layer Degree of rotation
- Kpoplayershadowradius--layer the size of the shadow below
All attribute lists can be found on the pop's GitHub. It's a long, long list, and the list is growing as developers have been contributing.
You may notice that the naming of these properties has some interesting places. We have a property named Kpopviewalpha, and the other is named Kpoplayerrotation. The cool place of pop lies in the properties that you can manipulate based on the attributes you pass in, as UIView well as the attributes you can manipulate CALayer . It's all up to you, you just have to let pop know that long list of the attributes that it supports, whether it's a view property, a layer property, or any type of property that you want to animate. Pop allows you to update any variable of the type you want, even if it is not related to the interface animation.
We set the Tovalue to [Nsvalue valuewithcgpoint:cgpointmake (2, 2)], which may seem a bit odd. Why should we put {2,2} this point (our x and y stretch values) into an NSValue object? Well, that's how pop works, and it's expected to be passed to the Tovalue parameter as an exact type of value. And this is worth the type that we add. It always expects an object, in this case, it wants a CGPoint converted NSValue object. Unfortunately this part of pop is a bit difficult to understand in the documentation, but it's also getting better as the developer contributes.
As for the fromvalue to consider, we did not set it in this example because pop did something cool: if you don't set it, it automatically calculates the current start value and starts here. It's great!
Finished viewing the integration set: Https://github.com/Cloudox/Motion-Design-for-iOS
All rights reserved: Http://blog.csdn.net/cloudox_
Motion Design for IOS (40)