[英]Dragging a UICollectionViewCell on another element
我想將UICollectionViewCell拖到另一個UIView或另一個元素上。 我創建了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;
}];
}
我可以將任何UICollectionViewCell拖放到UICollectionView中。 但是我不能將單元格拖動到屏幕上的另一個元素上。 例如另一個UICollectionView或UIView。
如果將clipToBounds屬性設置為“ false”,則可以將單元格拖動到任何位置,但它不會像滾動單元格一樣隱藏溢出內容。
在此圖片中, clipToBounds = false:
我不知道是否可能,但是為什么不將UIView放在UICollectionViewCell上並拖動該UIView? 當用戶嘗試拖動單元格時,只需隱藏該單元格並添加一個類似於該單元格的UIView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.