Reputation: 667
Currently I am implementing this to animate the movement of a cell:
- (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) {
}];
}
The issue I am having is whenever I move in the x direction, because my uicollectionview has horizontal scrolling and paging on, it will interrupt my touch events and stop the animation without moving the cell back to place.
Is there a way to either stop the uicollecitonview from scrolling during my touch event animations or a way to do this so that both can still work while the collection view is scrolling to new cell?
Upvotes: 1
Views: 626
Reputation: 2005
Set the UICollectionView's property canCancelContentTouches = NO.
Upvotes: 1