ios - 多个UIBezierPath拼接起来的运动轨迹,在执行动画的时候,动画出现卡顿,
ringa_lee
ringa_lee 2017-04-17 13:28:44
0
1
687

要实现动画的所设置的路径代码:

- (void)drawRect:(CGRect)rect {

    UIColor *color = [UIColor redColor];
    [color set];
    _aPath = [UIBezierPath bezierPath];
        [_aPath addArcWithCenter:CGPointMake(self.center.x, self.center.y-50) radius:50 startAngle:M_PI_2 endAngle:M_PI*2.f*3/4 clockwise:YES];
        [_aPath addArcWithCenter:CGPointMake(self.center.x, self.center.y) radius:100 startAngle:-M_PI_2 endAngle:M_PI*2.f*3/4 clockwise:YES];
        [_aPath addArcWithCenter:CGPointMake(self.center.x, self.center.y) radius:100 startAngle:-M_PI_2 endAngle:M_PI*2.f*3/4/3 clockwise:YES];
        [_aPath addArcWithCenter:CGPointMake(self.center.x, self.center.y+50) radius:50 startAngle:M_PI_2 endAngle:M_PI*2.f*3/4 clockwise:YES];

    _aPath.lineWidth = 5.0;
    _aPath.lineCapStyle = kCGLineCapRound; //线条拐角
   _aPath.lineJoinStyle = kCGLineCapRound; //终点处理
    [_aPath stroke];
}

下面的是我执行动画代码:

CAKeyframeAnimation *keyframeAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    keyframeAnimation.path = dr.aPath.CGPath;
    keyframeAnimation.repeatCount=1;
    keyframeAnimation.removedOnCompletion = NO;
    keyframeAnimation.fillMode = kCAFillModeForwards;
    keyframeAnimation.duration = 4.0f;
    keyframeAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    keyframeAnimation.delegate=self;
    [imageView.layer addAnimation:keyframeAnimation forKey:nil];
ringa_lee
ringa_lee

ringa_lee

全部回覆(1)
Ty80

執行動畫的時候,動畫出現卡頓

如果「卡頓」指的是它中間會停下來的話,那是因為插值方式。預設的插值方式是kCAAnimationLinear,關鍵影格直線相連進行插值。要讓動畫連續進行,可以簡單加一句:

keyframeAnimation.calculationMode = kCAAnimationPaced;

有更精細的需求,可以自己用keyTimes和timingFunctions來控制。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板