首页 > 学院 > 开发设计 > 正文

弹簧动画效果

2019-11-09 16:48:17
字体:
来源:转载
供稿:网友

github:https://github.com/potato512/SYAnimation

使用CaspringAnimation实现弹簧动画效果。

效果图:

代码示例:

- (void)sPRingAnimation{    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(120.0, 10.0, (self.view.frame.size.width - 10.0 - 120.0), 100.0)];    [self.view addSubview:view];    view.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.2];    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 10.0, 50.0, 30.0)];    label.backgroundColor = [UIColor redColor];    [view addSubview:label];        CASpringAnimation *spring = [CASpringAnimation animationWithKeyPath:@"position.x"];    spring.damping = 5;    spring.stiffness = 100;    spring.mass = 1;    spring.initialVelocity = 0;    spring.fromValue = @(label.layer.position.x);    spring.toValue = @(label.layer.position.x + 50.0);    spring.autoreverses = YES;    spring.repeatCount = MAXFLOAT;    spring.duration = spring.settlingDuration;        [label.layer addAnimation:spring forKey:spring.keyPath];}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表