ios - UICollectionViewCell 拖动动画

标签 ios objective-c uicollectionview uicollectionviewcell

目前我正在实现它来为单元格的移动设置动画:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event touchesForView:self.contentView] anyObject];
    CGPoint touchLocation = [touch locationInView:self];

    if (CGRectContainsPoint([UIScreen mainScreen].bounds, touchLocation))
    {
        dragging = YES;
        oldX = touchLocation.x;
        oldY = touchLocation.y;
    }
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event touchesForView:self.contentView] anyObject];
    CGPoint touchLocation = [touch locationInView:self.contentView];

    if (dragging)
    {
        self.frame = CGRectOffset(self.frame, touchLocation.x - oldX, touchLocation.y-oldY);
    }

}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    dragging = NO;
    [UIView animateWithDuration:0.3
                          delay:0.1
         usingSpringWithDamping:0.5
          initialSpringVelocity:1.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         self.frame = self.origionalFrame;
                     }
                     completion:^(BOOL finished) {
                     }];
}

我遇到的问题是每当我在 x 方向移动时,因为我的 uicollectionview 有水平滚动和分页,它会中断我的触摸事件并停止动画而不将单元格移回原位。

有没有一种方法可以阻止 uicollecitonview 在我的触摸事件动画期间滚动,或者有一种方法可以做到这一点,以便在 Collection View 滚动到新单元格时两者仍然可以工作?

最佳答案

设置 UICollectionView 的属性 canCancelContentTouches = NO。

关于ios - UICollectionViewCell 拖动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25128252/

相关文章:

iphone - UIWebView 从 javascript 音频播放器拦截 "setting movie path:"

iOS swift : App Transport Security has blocked a cleartext HTTP (http://) resource

ios - UITabBarController 动画的转换委托(delegate)

ios - 文本换行后 UITextView 大小不会改变大小,直到键入第二个字符

ios - IOS 上的 Ionic 3 背景音频

ios - 如何在 UICollectionView 中分割部分?

iphone - 从字符串中检索图像 url

iphone - 在 NSArray 中的字符串中搜索关键字

swift - 如何以编程方式选择 UICollectionView 的所有单元格

ios - UICollectionView 选择不会持续