OBjective-c 弹簧效果

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


你可能感兴趣的:(OBjective-c 弹簧效果)