iOS———实现抖动效果

来源:互联网 发布:centos识别不到硬盘 编辑:程序博客网 时间:2024/06/04 01:29

实现View 的抖动效果,直接调用下面方法

#pragma mark 抖动动画- (void)shakeAnimationForView:(UIView *) view{    // 获取到当前的View    CALayer *viewLayer = view.layer;    // 获取当前View的位置    CGPoint position = viewLayer.position;    // 移动的两个终点位置    CGPoint x = CGPointMake(position.x + 10, position.y);    CGPoint y = CGPointMake(position.x - 10, position.y);    // 设置动画    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];    // 设置运动形式    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];    // 设置开始位置    [animation setFromValue:[NSValue valueWithCGPoint:x]];    // 设置结束位置    [animation setToValue:[NSValue valueWithCGPoint:y]];    // 设置自动反转    [animation setAutoreverses:YES];    // 设置时间    [animation setDuration:.06];    // 设置次数    [animation setRepeatCount:3];    // 添加上动画    [viewLayer addAnimation:animation forKey:nil];}
0 0
原创粉丝点击