Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A way to create a custom timing function is by using the <strong>functionWithControlPoints::::</strong> factory method in CAMediaTimingFunction (there is a corresponding initWithControlPoints:::: init method as well). What this does is create a Bézier curve for your timing function. It is not an arbitrary curve, but Bézier curves are very powerful and flexible. It takes a little practice to get the hang of the control points. A tip: most drawing programs can create Bézier curves. Playing with those will give you a visual feedback on the curve you are representing with the control points. </p> <p>The <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Animation_Types_Timing/Articles/Timing.html">this link</a> points to apple's documentation. There is a short but useful section on how the pre-build functions are constructed from curves.</p> <p>Edit: The following code shows a simple bounce animation. For doing so, I created a composed timing function (<strong>values</strong> and <strong>timing</strong> NSArray properties) and gave each segment of the animation a different time length (<strong>keytimes</strong> property). In this way you can compose Bézier curves to compose more sophisticated timing for animations. <a href="http://watchingapple.com/2008/04/core-animation-creating-a-jack-in-the-box-with-cakeyframeanimation/">This</a> is a good article on this type of animations with a nice sample code.</p> <pre><code>- (void)viewDidLoad { UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 50.0)]; v.backgroundColor = [UIColor redColor]; CGFloat y = self.view.bounds.size.height; v.center = CGPointMake(self.view.bounds.size.width/2.0, 50.0/2.0); [self.view addSubview:v]; //[CATransaction begin]; CAKeyframeAnimation * animation; animation = [CAKeyframeAnimation animationWithKeyPath:@"position.y"]; animation.duration = 3.0; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; NSMutableArray *values = [NSMutableArray array]; NSMutableArray *timings = [NSMutableArray array]; NSMutableArray *keytimes = [NSMutableArray array]; //Start [values addObject:[NSNumber numberWithFloat:25.0]]; [timings addObject:GetTiming(kCAMediaTimingFunctionEaseIn)]; [keytimes addObject:[NSNumber numberWithFloat:0.0]]; //Drop down [values addObject:[NSNumber numberWithFloat:y]]; [timings addObject:GetTiming(kCAMediaTimingFunctionEaseOut)]; [keytimes addObject:[NSNumber numberWithFloat:0.6]]; // bounce up [values addObject:[NSNumber numberWithFloat:0.7 * y]]; [timings addObject:GetTiming(kCAMediaTimingFunctionEaseIn)]; [keytimes addObject:[NSNumber numberWithFloat:0.8]]; // fihish down [values addObject:[NSNumber numberWithFloat:y]]; [keytimes addObject:[NSNumber numberWithFloat:1.0]]; //[timings addObject:GetTiming(kCAMediaTimingFunctionEaseIn)]; animation.values = values; animation.timingFunctions = timings; animation.keyTimes = keytimes; [v.layer addAnimation:animation forKey:nil]; //[CATransaction commit]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload