1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| 触摸针对的是整个View,是视图控制器自带方法,用的时候直接重写 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; //拿到当前点击位置 通过UITouch UITouch *nowTouch = touches.anyObject; CGPoint location = [nowTouch locationInView:self.view]; //弹性动画 //usingSpringWithDamping 阻尼系数 0-1 越小越明显 //initialSpringVelocity 初始速度 [UIView animateWithDuration:0.2 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0 options:0 animations:^{ //更新图片坐标-加动画 _imageView.bounds = CGRectMake(0, 0, 120, 120); _imageView.center = location; } completion:^(BOOL finished){ [UIView animateWithDuration:0.2 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0 options:0 animations:^{ _imageView.bounds = CGRectMake(0, 0, 80, 80); } completion:nil]; }]; }
|