您的位置:首页 > 移动开发 > Objective-C

OBjective-c 弹簧效果

2015-12-22 00:00 447 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: