【问题标题】:UICollectionView drag and drop remove translucent cellUICollectionView 拖放移除半透明单元格
【发布时间】:2019-06-05 01:08:20
【问题描述】:

我正在使用 iOS 11 拖放 API 进行重新排序,并希望删除开始拖动时出现的半透明单元格。可能吗?对于拖动,我只使用 UICollectionViewDragDelegate 所需的方法:

- (nonnull NSArray<UIDragItem *> *)collectionView:(nonnull UICollectionView *)collectionView
                     itemsForBeginningDragSession:(nonnull id<UIDragSession>)session
                                      atIndexPath:(nonnull NSIndexPath *)indexPath {
    NSItemProvider *itemProvider = [NSItemProvider new];
    UIDragItem *dragItem = [[UIDragItem alloc] initWithItemProvider:itemProvider];

    return @[dragItem];
}

【问题讨论】:

  • 你能得到单元格开始拖动的方法吗?
  • 不。如果你想要 ios 对象的自定义行为,那么你需要自定义它

标签: ios objective-c uicollectionview drag-and-drop


【解决方案1】:

您可以在拖放生命周期中通过覆盖 dragStateDidChange(_ dragState: UICollectionViewCell.DragState) 来自定义您的单元格

class MyCell: UICollectionViewCell {

    //...
    override func dragStateDidChange(_ dragState: UICollectionViewCell.DragState) {

        switch dragState {
        case .none:
            self.layer.opacity = 1
        case .lifting:
            return
        case .dragging:
            self.layer.opacity = 0

        }
    }
}

【讨论】:

    【解决方案2】:

    在您的单元格类上重写此方法:

    override func dragStateDidChange(_ dragState: UICollectionViewCell.DragState) {
    
        switch dragState {
        case .none:
    
            self.layer.opacity = 1
    
        case .lifting:
    
            return
    
        case .dragging:
    
            self.layer.opacity = 0
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-09-25
      • 1970-01-01
      • 2020-06-14
      • 2023-04-08
      • 1970-01-01
      • 2013-04-17
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多