目前我正在实现它来为单元格的移动设置动画:
- (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/