An analysis of iOS animation

Source: Internet
Author: User

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
    • Animationdemo

Several animation effects are implemented in the instance code:
    1. Fade-in/fade out;
    2. Flashing
    3. Drop down/Shrink menu;
    4. Mobile
    5. Zoom In/Zoom Out
    6. Constant rotation;
    7. 3D rotation;
    8. Clock
    9. Fast rotation;

Effect


An analysis of iOS animation

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.