I want to drag a UICollectionViewCell on another UIView or another element. I've created a subclass of UICollectionViewCell.
This is my cell class, subclass of UICollectionViewCell:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.dragObject=self;
self.homePosition = CGPointMake(self.frame.origin.x,
self.frame.origin.y);
[self.superview.superview bringSubviewToFront:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:self.superview];
CGRect newDragObjectFrame = CGRectMake(touchPoint.x - touchOffset.x,
touchPoint.y - touchOffset.y,
self.frame.size.width,
self.frame.size.height);
self.frame = newDragObjectFrame;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect newFrame = CGRectMake(self.homePosition.x, self.homePosition.y,
self.frame.size.width,
self.frame.size.height);
[UIView animateWithDuration:0.2
animations:^{
self.frame = newFrame;
}];
}
I can drag and drop any UICollectionViewCell in UICollectionView. But I can't drag a cell on another element on the screen. For example another UICollectionView or UIView.
If I set clipToBounds property to "false" then I can drag a cell on anywhere but it doesn't hide overflow content, like scrolled cells.
in this picture, clipToBounds=false: