iOS动画

作者: 零纪年 | 来源:发表于2015-07-06 16:12 被阅读1316次

    iOS动画有隐式和显示之分。隐式动画指的是,无须创建动画对象,只需改变动画层的属性,让核心动画自己去完成动画效果, 例如(CATransaction)。显示动画指的是,需要自己创建和管理动画对象,并且将它们应用到动画层,才能显示动画效果。

    CGRectInset: Returns a rectangle that is smaller or larger than the source rectangle, with the same center point.

    创建一个矩形框, 以原先frame的center为中心, 可做绕一个圈转的动画:

    CGMutablePathRefcurvedPath =CGPathCreateMutable();

    CGRectcircleContainer =CGRectInset(self.frontView.frame,self.frontView.bounds.size.width/2-13,self.frontView.bounds.size.width/2-13);

    CGPathAddEllipseInRect(curvedPath,NULL, circleContainer);

    CAKeyframeAnimation*pathAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];

    pathAnimation.calculationMode=kCAAnimationPaced;

    pathAnimation.fillMode=kCAFillModeForwards;

    pathAnimation.removedOnCompletion=NO;

    pathAnimation.repeatCount=INFINITY;

    pathAnimation.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];

    pathAnimation.duration=5.0;

    pathAnimation.path= curvedPath;

    CGPathRelease(curvedPath);

    CAKeyframeAnimation关键帧动画也可做一系列形变:

    CAKeyframeAnimation*scaleY = [CAKeyframeAnimationanimationWithKeyPath:@"transform.scale.y"];

    scaleY.duration=1.5;

    scaleY.values=@[@1.0,@1.1,@1.0];

    scaleY.keyTimes=@[@0.0,@0.5,@1.0];

    scaleY.repeatCount=INFINITY;

    scaleY.autoreverses=YES;

    scaleX.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [self.frontView.layeraddAnimation:scaleYforKey:@"scaleYAnimation"];

    同理scaleX

    相关文章

      网友评论

        本文标题:iOS动画

        本文链接:https://www.haomeiwen.com/subject/lbmyqttx.html