IOS 手势拖拽弹簧效果

  1. 添加手势

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);
}


你可能感兴趣的:(ios,ipad)