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];}
新闻热点
疑难解答