OC, oc Language

Source: Internet
Author: User

OC, oc Language
Overview

  • Introduction

    • CAKeyframeAnimation is also called a key frame animation.
    • CAKeyframeAnimation is a subclass of the abstract class CAPropertyAnimation. It can be directly used.
    • Specify the animation attributes through the values and path attributes.
  • Notes

    • If the path attribute is specified, the values attribute is ignored.
    • CABasicAnimation is equivalent to CAKeyframeAnimation with only two key frames.
Common attributes of Key Frame Animation
  • Values (NSArray *)

    • Multiple key frame values
    • Similar to the fromValue and toValue values of CABasicAnimation
  • Path (CGPathRef)

    • Animation execution path
    • You can draw a path by drawing
  • KeyTimes (NSArray *)

    • Execution time of each key frame
    • NSNumber type
    • If this parameter is not specified, the duration of all key frames is equal to the animation duration.
  • TimingFunctions (NSArray *)

    • Array of speed control functions
  • CalculationMode (NSString *)

    • Specifies the animation attribute of the key frame.
    • If this value is specified, the keyTimes and timingFunctions attribute values are ignored.
    • Default Value: kCAAnimationLinear
  • RotationMode (NSString *)

    • Specify the rotation mode. The default value is nil.
Example
  • Implementation

    • Draw the besell curve by listening to the touch events of the UI control that executes the animation.
    • Create a Key Frame Animation and specify the keyPath attribute of the animation.
    • Use the beiser curve as the animation execution path.
    • Add an animation to a specified layer
  • Implementation steps (subclass of custom UIView)

    • Save the besher path using the member attributes
    @property (nonatomic, strong) UIBezierPath *path;
    • Listen to the status of the touch event and draw the beser Curve

      • Start
      // Determine the start point-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {// obtain the current touch point UITouch * touch = [touches anyObject]; CGPoint curretnPoint = [touch locationInView: self]; // create path UIBezierPath * path = [UIBezierPath bezierPath]; [path moveToPoint: curretnPoint]; // save path self. path = path ;}
      • Mobile
      // Add a line-(void) touchesMoved :( NSSet *) touches withEvent :( UIEvent *) event {// obtain the current touch point UITouch * touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView: self]; // Add a line [self. path addLineToPoint: currentPoint]; // redraw the curve and display it on the layer [self setNeedsDisplay];}
      • End (create an animation)
      -(Void) touchesEnded :( NSSet *) touches withEvent :( UIEvent *) event {// create an animation CAKeyframeAnimation * animation = [CAKeyframeAnimation animation]; // specify the attributes of the animation, animation. keyPath = @ "position"; // sets the animation execution path, animation. path = self. path. CGPath; // set the animation execution time to animation. duration = 1; // set the animation repetition rate to animation. repeatCount = MAXFLOAT; // Add the animation to the corresponding layer [[self. subviews firstObject] layer] addAnimation: animation forKey: nil];}
    • Show the path to the Layer

    // Draw the path-(void) drawRect :( CGRect) rect {[self. path stroke];}

     

Related Article

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.