ViewController.m文件
動畫
// // ViewController.m // 彈簧 // // Created by DC017 on 15/12/22. // Copyright © 2015年 DC017. All rights reserved. // #import "ViewController.h" @interface ViewController () { UIImageView * image; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //建立圖像 image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ball"]]; image.frame=CGRectMake(375/2.0, 667/2, 50,50); [self.view addSubview:image]; } #pragma mark 點擊事件 -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch=[touches anyObject]; CGPoint XY=[touch locationInView:self.view]; //建立彈性動畫 //damping阻尼 : 返回0-1,接近0,彈性效果越明顯 //velocity:彈性復原速度 [UIView animateWithDuration:5.0 delay:0 usingSpringWithDamping:0.1 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveLinear animations:^{ image.center=XY;//最終小球的位置 } completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end