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; 
          }]; 

} 

enter image description here

我可以拖動和UICollectionView降大任於UICollectionViewCell。但我無法在屏幕上的另一個元素上拖動單元格。例如另一個UICollectionView或UIView。

如果我將clipToBounds屬性設置爲「false」,那麼我可以在任何位置拖動單元格,但不會隱藏溢出內容(如滾動單元格)。

在這張照片

clipToBounds =假:

enter image description here

回答

1

我不知道,如果是是可以或不可以,但你爲什麼不只是把一個UIView超過UICollectionViewCell並拖動這個的UIView ? 當用戶試圖拖動單元格時,只需隱藏單元格並添加一個像單元格一樣操作的UIView。

+0

輝煌,謝謝... – onivi

相關問題