美文网首页
NSItemProvider 拖拽item

NSItemProvider 拖拽item

作者: Smallwolf_JS | 来源:发表于2022-08-01 14:45 被阅读0次
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        if (@available(iOS 11.0, *)) {
            UIDragInteraction *dragInteraction = [[UIDragInteraction alloc] initWithDelegate:self];
            dragInteraction.enabled = YES;
            [self addInteraction:dragInteraction];
        }
    }
    return self;
}


#pragma mark - UIDragInteractionDelegate

- (nonnull NSArray<UIDragItem *> *)dragInteraction:(nonnull UIDragInteraction *)interaction itemsForBeginningSession:(nonnull id<UIDragSession>)session NS_AVAILABLE_IOS(11.0) {
    NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithObject:self.tagSpecial];
    UIDragItem *dragItem = [[UIDragItem alloc] initWithItemProvider:itemProvider];
    return @[dragItem];
}

相关文章

网友评论

      本文标题:NSItemProvider 拖拽item

      本文链接:https://www.haomeiwen.com/subject/kkjrwrtx.html