iOS9 视图弹出的弹簧效果
Spring Animationring Animation):
在IOS7开始,系统动画效果广泛应用Spring Animation:
[UIView animateWithDuration:4.0 // 动画时长 delay:0.0 // 动画延迟 usingSpringWithDamping:1.0 // 类似弹簧振动效果 0~1 initialSpringVelocity:5.0 // 初始速度 options:UIViewAnimationOptionCurveEaseInOut // 动画过渡效果 animations:^{ // code... CGPoint point = _imageView.center; point.y += 150; [_imageView setCenter:point]; } completion:^(BOOL finished) { // 动画完成后执行 // code... [_imageView setAlpha:1]; }];
usingSpringWithDamping:它的范围为 0.0f 到 1.0f ,数值越小「弹簧」的振动效果越明显。
initialSpringVelocity:初始的速度,数值越大一开始移动越快。值得注意的是,初始速度取值较高而时间较短时,也会出现反弹情况。
转:Spring Animation 是线性动画或 ease-out 动画的理想替代品。由于 iOS 本身大量使用的就是 Spring Animation,用户已经习惯了这种动画效果,因此使用它能使 App 让人感觉更加自然,用 Apple 的话说就是「instantly familiar」。此外,Spring Animation 不只能对位置使用,它适用于所有可被添加动画效果的属性。
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, strong)UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *iamge = [UIImage imageNamed:@"chengxuyuan.png"];
CGSize size = iamge.size;
NSLog(@"the size is %@", NSStringFromCGSize(size));
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
_imageView.image = [UIImage imageNamed:@"chengxuyuan.png"];
[self.view addSubview:_imageView];
UITapGestureRecognizer *tapRecognizerRadar = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGestureRadar:)];
[_imageView addGestureRecognizer:tapRecognizerRadar];
_imageView.userInteractionEnabled = YES;
CGAffineTransform fromTransform = CGAffineTransformScale(_imageView.transform, 0.2, 0.2);
[_imageView setTransform:fromTransform];
// CGAffineTransform toTransform = CGAffineTransformConcat(_imageView.transform, CGAffineTransformInvert(_imageView.transform));
// CGAffineTransform toTransform2 = CGAffineTransformScale(toTransform, 1.3, 1.3);
[UIView animateWithDuration:1.0 // 动画时长
delay:0.0 // 动画延迟
usingSpringWithDamping:0.4 // 类似弹簧振动效果 0~1
initialSpringVelocity:5.0 // 初始速度
options:UIViewAnimationOptionCurveEaseInOut // 动画过渡效果
animations:^{
// code...
// CGPoint point = _imageView.center;
// point.y += 150;
// [_imageView setCenter:point];
[_imageView setTransform:fromTransform];
_imageView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
} completion:^(BOOL finished) {
// 动画完成后执行
// code...
[_imageView setAlpha:1];
}];
//
}
- (void)handleTapGestureRadar:(UITapGestureRecognizer *)sender {
[UIView animateWithDuration:0.35 animations:^{
// _imageView.frame = self.view.bounds;
_imageView.transform = CGAffineTransformMakeScale(20.0f, 20.0f);
_imageView.alpha = 0;
} completion:^(BOOL finished) {
}];
}