There are three main ways to call an iOS animation:
1. UIView's animated code block
2. UIView [begin, Commit] mode
3. Cabasicanimation method
UIView Animation code block calls
[UIView animatewithduration:timeinterval animations:^{weaktableview.frame = CGRectMake (0,-height, WeakSelf.frame.size.width, height); [Weaktableview setalpha:0];}];
Note : References to objects in a block of code are declared as __weak, or memory leaks are caused.
[begin, Commit] mode
[UIView Beginanimations:nil Context:nil]; [UIView Setanimationduration:timeinterval]; [View Sethidden:hide]; [UIView commitanimations];
Start/End Animation message definition form:
Start Animation-(void) Animationdidstart: (NSString *) Animationid context: (void *) context//end Animation-(void) Animationdidstop: ( NSString *) Animationid finished: (NSNumber *) finished context: (void *) context
Two ways of comparing
- Animate with code blocks using the Uiviewanimationoptioncurveeaseinout and Uiviewanimationoptiontransitionnone animation options. During the playback of an animation, the user's interaction is temporarily unavailable.
- animating in [Begin,commit] mode is more flexible than blocks of code, and more options can be configured. In addition, the Animationid and context parameters allow you to configure the method that is called when the animation starts/ends.
Cabasicanimation Common key valuesNote:The key values correspond to the related properties of the Calayer and animate by changing the values of those properties.
- transform.scale.x -wide proportional conversion
- Transform.scale.y High Proportional conversion
- Transform.rotation.z rotation of planar circles
- Opacity Transparency
- Margin shows the size of the content in the view
- Zposition The front and back order of the screen hierarchy
- BackgroundColor Background color
- Cornerradius Rounded Corners
- Width of the borderWidth edge
- Bounds layer's boundary matrix, similar to frame
- Contents Content, for example: changes in the picture
- Contentsrect content can use the size of a layer
- Frame matrix for frame view
- Hidden Hidden state
- Mask masking background and transparency of content display
- Maskstobounds Determines whether the child layer is cut off from the boundary of the layer
- The position of the position layer in its parent layer
- Shadowcolor Shadow Color
- Shadowoffset Shadow offset
- Shadowopacity Shadow Transparency
- Shadowradius Shadow Fillet
Calling methods
Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@ "transform"];
Time function Setting method
Animation.timingfunction = [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseout];
Common functions
- Kcamediatimingfunctionlinear Linear increment
- Kcamediatimingfunctioneasein Slow-forward, that is, the animation starts slowly, and then gradually accelerates
- Kcamediatimingfunctioneaseout Fast-forward slow-out, that is, the animation starts faster, and then gradually slow
- Kcamediatimingfunctioneaseineaseout Slow-forward-acceleration-slow out
- Kcamediatimingfunctiondefault using control points [(0.0,0.0), (0.25,0.1), (0.25,0.1), (1.0,1.0)], need to ensure that animations use the default timings
Two ways to cycle the animation timer NstimerCreate/Start
Nstimer *timer = [Nstimer scheduledTimerWithTimeInterval:timeIntervaltarget:self.animationCollectionsselector: AnimationSelectoruserInfo:nilrepeats:YES];
Stop
[Timer invalidate];timer = nil;
CadiplaylinkCreate/Start
Cadisplaylink *display = [Cadisplaylink displayLinkWithTarget:self.animationCollections selector:animationselector] ; [Display Addtorunloop:[nsrunloop Currentrunloop] formode:nsdefaultrunloopmode];
Stop
[Player Invalidate];timer = nil;
Loop Play Cabasicanimation
Animation.repeatcount = Flt_max;animaiton.removedoncompletion = NO;
Code instance
Several animation effects are implemented in the instance code:
- Fade-in/fade out;
- Flashing
- Drop down/Shrink menu;
- Mobile
- Zoom In/Zoom Out
- Constant rotation;
- 3D rotation;
- Clock
- Fast rotation;
Effect
An analysis of iOS animation