相关疑难解决方法(0)

UIView摇动动画

我按下按钮时试图让UIView摇晃.

我正在调整我在http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/上找到的代码.

但是,通过尝试调整以下代码来动摇UIView,它不起作用:

- (void)animate {
    const int numberOfShakes = 8;
    const float durationOfShake = 0.5f;
    const float vigourOfShake = 0.1f;

    CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation];

    CGRect frame = lockView.frame;

    CGMutablePathRef shakePath = CGPathCreateMutable();
    CGPathMoveToPoint(shakePath, NULL, CGRectGetMinX(frame), CGRectGetMinY(frame));

    for (int index = 0; index < numberOfShakes; ++index) {
        CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) - frame.size.width * vigourOfShake, CGRectGetMinY(frame));

        CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) + frame.size.width * vigourOfShake, CGRectGetMinY(frame));
    }

    CGPathCloseSubpath(shakePath);

    shakeAnimation.path = shakePath;
    shakeAnimation.duration = durationOfShake;


    [lockView.layer addAnimation:shakeAnimation forKey:@"frameOrigin"];

}
Run Code Online (Sandbox Code Playgroud)

iphone animation cocoa-touch core-animation ios

77
推荐指数
5
解决办法
4万
查看次数

标签 统计

animation ×1

cocoa-touch ×1

core-animation ×1

ios ×1

iphone ×1