【问题标题】:Dragging a UICollectionViewCell on another element在另一个元素上拖动 UICollectionViewCell
【发布时间】:2013-10-06 11:32:23
【问题描述】:

我想将 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;
                             }];

}

我可以在 UICollectionView 中拖放任何 UICollectionViewCell。但是我不能在屏幕上的另一个元素上拖动一个单元格。例如另一个 UICollectionView 或 UIView。

如果我将 clipToBounds 属性设置为“false”,那么我可以将一个单元格拖动到任何地方,但它不会隐藏溢出内容,例如滚动的单元格。

在这张图片中,clipToBounds=false:

【问题讨论】:

    标签: ios drag-and-drop uicollectionview uicollectionviewcell cliptobounds


    【解决方案1】:

    我不知道这是否可能,但为什么你不只是在 UICollectionViewCell 上放置一个 UIView 并拖动这个 UIView? 当用户试图拖动一个单元格时,只需隐藏该单元格并添加一个 UIView 就像该单元格一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 2021-09-26
      相关资源
      最近更新 更多