1
我想在另一个UIView或其他元素上拖动UICollectionViewCell。 我已经创建了UICollectionViewCell的子类。在另一个元素上拖动UICollectionViewCell
这是我的手机类,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;
}];
}
我可以拖动和UICollectionView降大任于UICollectionViewCell。但我无法在屏幕上的另一个元素上拖动单元格。例如另一个UICollectionView或UIView。
如果我将clipToBounds属性设置为“false”,那么我可以在任何位置拖动单元格,但不会隐藏溢出内容(如滚动单元格)。
在这张照片,clipToBounds =假:
辉煌,谢谢... – onivi