您的位置:首页 > 移动开发 > IOS开发

IOS 手势拖拽弹簧效果

2015-06-24 00:00 525 查看
添加手势

UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self    action:@selector(dragContentView:)];
[self.contentView addGestureRecognizer:recognizer];

2.实现效果,其中托转参数决定弹簧效果的强弱

- (void)dragContentView:(UIPanGestureRecognizer *)pan
{
if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateCancelled) {
[UIView animateWithDuration:0.25 animations:^{
pan.view.transform = CGAffineTransformIdentity;
}];
}

CGPoint translation = [pan translationInView:pan.view];
pan.view.transform = CGAffineTransformMakeTranslation(translation.x * 0.2, 0);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息