美文网首页iosiOS_UIKit
UIDragInteraction拖拽UIDropInterac

UIDragInteraction拖拽UIDropInterac

作者: 絮语时光杨 | 来源:发表于2018-05-14 11:23 被阅读1次

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 <NSObject>
@required
//提供数据源 长按UI开始拖拽

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

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

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

  • (BOOL)dropInteraction:(UIDropInteraction *)interaction canHandleSession:(id<UIDropSession>)session;
    //Drag的UI元素进入Drop的区域
  • (void)dropInteraction:(UIDropInteraction *)interaction sessionDidEnter:(id<UIDropSession>)session;
    //第二次判断是否可以接收 无法接收用UIDropOperationCancel
  • (UIDropProposal *)dropInteraction:(UIDropInteraction *)interaction sessionDidUpdate:(id<UIDropSession>)session;
    //Drag的UI元素离开Drop的区域
  • (void)dropInteraction:(UIDropInteraction *)interaction sessionDidExit:(id<UIDropSession>)session;
    //取出来自drag的数据
    1
    NSLog(@"%f,%f",[session locationInView:self.view].x,[session locationInView:self.view].y)
  • (void)dropInteraction:(UIDropInteraction *)interaction performDrop:(id<UIDropSession>)session;
    //drop结束
  • (void)dropInteraction:(UIDropInteraction *)interaction concludeDrop:(id<UIDropSession>)session;
    //整个Drag和Drop结束
  • (void)dropInteraction:(UIDropInteraction *)interaction sessionDidEnd:(id<UIDropSession>)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<UIDragAnimating>)animator;

相关文章

  • UIDragInteraction拖拽UIDropInterac

    if (IOS11) {UIDragInteraction* drag = [[UIDragInteraction...

  • UIDragInteraction.h

  • Drag and Drop for iOS11 (Drag to

    在上一篇文章中我们已经实现了用UIDragInteraction 和UIView的新属性pasteConfigur...

  • 拖拽操作

    应用: 1.拖拽排序2.拖拽上传3.拖拽裁剪 拖拽流程 确定可拖拽的内容-->开始拖拽-->拖拽过程-->结束拖拽...

  • Html5 + Css 3 文件拖拽上传功能

    拖拽上传文件功能 拖拽事件 拖拽元素ondrag 应用于拖拽元素,整个拖拽过程都会调用ondragstart应用...

  • 拖拽上传

    拖拽事件 拖拽元素ondrag 应用于拖拽元素,整个拖拽过程都会调用ondragstart应用于拖拽元素,...

  • js:拖拽事件

    拖拽事件 ondragstart当拖拽元素被开始拖拽时,event:拖拽元素。[从操作系统向浏览器拖拽文件不会触发...

  • HTML 5 拖拽

    @(HTML5)[HTML 5拖拽] [TOC] 十三、HTML 5 拖拽 HTML 5 拖拽事件 图片自带拖拽功...

  • JQuery UI 拖拽排序

    禁用拖拽: 启用拖拽:

  • MacOS 开发(十六) : 文件拖拽

    文件拖拽的核心是拖拽目标视图 (DragDestinationView),此方法会检测目标是否可拖拽类型,拖拽文件...

网友评论

    本文标题:UIDragInteraction拖拽UIDropInterac

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