弹簧动画效果

来源:互联网 发布:淘宝美工是做什么的 编辑:程序博客网 时间:2024/06/11 17:45

githubhttps://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];}




0 0
原创粉丝点击