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

相关问题