UIDragInteraction拖拽UIDropInteraction

if (IOS11) {
UIDragInteraction* drag = [[UIDragInteraction alloc] initWithDelegate:self];
[self addInteraction:drag];
self.userInteractionEnabled = true;
}
**************代理
API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos) @protocol UIDragInteractionDelegate
@required
//提供数据源 长按UI开始拖拽

  • (NSArray *)dragInteraction:(UIDragInteraction *)interaction itemsForBeginningSession:(id)session;
    @optional
    //提供UITargetedDragPreview的相关信息 长按UI是有个lift(UI举起效果,系统自动生成)
    //返回nil 没有效果; 不实现该方法 interaction.view自动生成UITargetedDragPreview
  • (nullable UITargetedDragPreview *)dragInteraction:(UIDragInteraction *)interaction previewForLiftingItem:(UIDragItem *)item session:(id)session;
    //drag发生时调用
  • (void)dragInteraction:(UIDragInteraction *)interaction willAnimateLiftWithAnimator:(id)animator session:(id)session;
    //将要开始drag
  • (void)dragInteraction:(UIDragInteraction *)interaction sessionWillBegin:(id)session;
    //是否允许数据移动 app内移动有效,跨app总是复制数据
  • (BOOL)dragInteraction:(UIDragInteraction *)interaction sessionAllowsMoveOperation:(id)session;
    //是否允许跨应用程序进行drag ipad
  • (BOOL)dragInteraction:(UIDragInteraction *)interaction sessionIsRestrictedToDraggingApplication:(id)session;
    //设置预览视图是否显示原始大小
  • (BOOL)dragInteraction:(UIDragInteraction *)interaction prefersFullSizePreviewsForSession:(id)session;
    //已经结束移动
  • (void)dragInteraction:(UIDragInteraction *)interaction sessionDidMove:(id)session;
    //drag将要结束时调用
  • (void)dragInteraction:(UIDragInteraction *)interaction session:(id)session willEndWithOperation:(UIDropOperation)operation;
    //drag已经结束时调用
  • (void)dragInteraction:(UIDragInteraction *)interaction session:(id)session didEndWithOperation:(UIDropOperation)operation;
    //拖拽源进行了放置操作后调用
  • (void)dragInteraction:(UIDragInteraction *)interaction sessionDidTransferItems:(id)session;
    //设置是否允许向拖拽中的项目添加数据 返回数据载体数组 drag时点击拖拽的组件调用
  • (NSArray *)dragInteraction:(UIDragInteraction *)interaction itemsForAddingToSession:(id)session withTouchAtPoint:(CGPoint)point;
    //设置允许进行拖拽中追加数据的拖拽行为会话
  • (nullable id)dragInteraction:(UIDragInteraction *)interaction sessionForAddingItems:(NSArray> *)sessions withTouchAtPoint:(CGPoint)point;
    //将要向拖拽组件中追加数据时调用
  • (void)dragInteraction:(UIDragInteraction *)interaction session:(id)session willAddItems:(NSArray *)items forInteraction:(UIDragInteraction *)addingInteraction;
    //设置拖拽动作取消的视图动画 返回nil则消除动画
  • (nullable UITargetedDragPreview *)dragInteraction:(UIDragInteraction *)interaction previewForCancellingItem:(UIDragItem *)item withDefault:(UITargetedDragPreview *)defaultPreview;
    //drag动画将要取消时调用
  • (void)dragInteraction:(UIDragInteraction *)interaction item:(UIDragItem *)item willAnimateCancelWithAnimator:(id)animator;

API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos) @protocol UIDropInteractionDelegate

@optional
//是否可以处理来自Drag的数据

  • (BOOL)dropInteraction:(UIDropInteraction *)interaction canHandleSession:(id)session;
    //Drag的UI元素进入Drop的区域
  • (void)dropInteraction:(UIDropInteraction *)interaction sessionDidEnter:(id)session;
    //第二次判断是否可以接收 无法接收用UIDropOperationCancel
  • (UIDropProposal *)dropInteraction:(UIDropInteraction *)interaction sessionDidUpdate:(id)session;
    //Drag的UI元素离开Drop的区域
  • (void)dropInteraction:(UIDropInteraction *)interaction sessionDidExit:(id)session;
    //取出来自drag的数据
    1
    NSLog(@"%f,%f",[session locationInView:self.view].x,[session locationInView:self.view].y)
  • (void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id)session;
    //drop结束
  • (void)dropInteraction:(UIDropInteraction *)interaction concludeDrop:(id)session;
    //整个Drag和Drop结束
  • (void)dropInteraction:(UIDropInteraction *)interaction sessionDidEnd:(id)session;
    //手指松开,控制Drag Preview 如何自然的过渡到Drop之后的Preview
  • (nullable UITargetedDragPreview *)dropInteraction:(UIDropInteraction *)interaction previewForDroppingItem:(UIDragItem *)item withDefault:(UITargetedDragPreview *)defaultPreview;
    //手指松开Drop时,控制Drop区域的其他UI元素如何展示动画
  • (void)dropInteraction:(UIDropInteraction *)interaction item:(UIDragItem *)item willAnimateDropWithAnimator:(id)animator;

你可能感兴趣的:(UIDragInteraction拖拽UIDropInteraction)