< UIKit >

UIDragInteraction.h

2019-06-24  本文已影响0人  zhYx_

#if USE_UIKIT_PUBLIC_HEADERS || !__has_include(<UIKitCore/UIDragInteraction.h>)
//
//  UIDragInteraction.h
//  UIKit
//
//  Copyright © 2017-�2018 Apple Inc. All rights reserved.
//

#import <UIKit/UIDropInteraction.h>
#import <UIKit/UIInteraction.h>
#import <UIKit/UIViewAnimating.h>

NS_ASSUME_NONNULL_BEGIN

@protocol UIDragInteractionDelegate, UIDragSession;
@class UIDragItem, UITargetedDragPreview;



///!!!: 拖动动画 <协议>
API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos) @protocol UIDragAnimating <NSObject>

// 添加自定义拖拽动画(将抵消系统自带动画)
- (void)addAnimations:(void (^)(void))animations;
// 拖拽动画完成之后的自定义动画
- (void)addCompletion:(void (^)(UIViewAnimatingPosition finalPosition))completion;

@end





#pragma mark - 拖动相关的交互 Class
#pragma mark
UIKIT_EXTERN API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos) @interface UIDragInteraction : NSObject <UIInteraction>

#pragma mark |实例化|
- (instancetype)initWithDelegate:(id<UIDragInteractionDelegate>)delegate NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

/// 代理
@property (nonatomic, nullable, readonly, weak) id<UIDragInteractionDelegate> delegate;
/// 是否允许在拖拽中识别其他手势(默认:NO)
@property (nonatomic) BOOL allowsSimultaneousRecognitionDuringLift;
/// 是否允许此次拖动
@property (nonatomic, getter=isEnabled) BOOL enabled;
/// 根据设备相关信息决定是否允许此次拖动
@property (class, nonatomic, readonly, getter=isEnabledByDefault) BOOL enabledByDefault;

@end





///!!!: 代理 <协议>
/*
 概述
    - 用于配置和控制拖动交互的界面
 */
API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos) @protocol UIDragInteractionDelegate <NSObject>

@required
// 设置拖动的Item(如果返回空数组,则不会开始拖动)
- (NSArray<UIDragItem *> *)dragInteraction:(UIDragInteraction *)interaction itemsForBeginningSession:(id<UIDragSession>)session;

@optional
// 设置拖动之前的抬起动画(返回nil:没有拖动动画;未实现:使用interaction.view初始化的UITargetedDragPreview)
- (nullable UITargetedDragPreview *)dragInteraction:(UIDragInteraction *)interaction previewForLiftingItem:(UIDragItem *)item session:(id<UIDragSession>)session;
// 拖动之前的抬起动画将要开始
- (void)dragInteraction:(UIDragInteraction *)interaction willAnimateLiftWithAnimator:(id<UIDragAnimating>)animator session:(id<UIDragSession>)session;
// 拖动之前的抬起动画已经完成
- (void)dragInteraction:(UIDragInteraction *)interaction sessionWillBegin:(id<UIDragSession>)session;

// 是否允许拖动(默认:YES)
- (BOOL)dragInteraction:(UIDragInteraction *)interaction sessionAllowsMoveOperation:(id<UIDragSession>)session;
// 是否允许跨App拖动(在支持分屏功能的设备上有效;默认:NO)
- (BOOL)dragInteraction:(UIDragInteraction *)interaction sessionIsRestrictedToDraggingApplication:(id<UIDragSession>)session;
// 是否以原始大小浏览拖动中的Item(默认:NO)
- (BOOL)dragInteraction:(UIDragInteraction *)interaction prefersFullSizePreviewsForSession:(id<UIDragSession>)session;
// 开始拖动时获取Item拖动之前的位置
- (void)dragInteraction:(UIDragInteraction *)interaction sessionDidMove:(id<UIDragSession>)session;
// 拖动将要结束
- (void)dragInteraction:(UIDragInteraction *)interaction session:(id<UIDragSession>)session willEndWithOperation:(UIDropOperation)operation;
// 拖动已经结束
- (void)dragInteraction:(UIDragInteraction *)interaction session:(id<UIDragSession>)session didEndWithOperation:(UIDropOperation)operation;
// 拖动已经结束,并收到拖动Item的相关数据
- (void)dragInteraction:(UIDragInteraction *)interaction sessionDidTransferItems:(id<UIDragSession>)session;

#pragma mark |向正在进行的拖动中加入Item|
// 把其他Item加入到拖动会话
- (NSArray<UIDragItem *> *)dragInteraction:(UIDragInteraction *)interaction itemsForAddingToSession:(id<UIDragSession>)session withTouchAtPoint:(CGPoint)point;
// 要添加的Item准备加入到哪个拖动会话
- (nullable id<UIDragSession>)dragInteraction:(UIDragInteraction *)interaction sessionForAddingItems:(NSArray<id<UIDragSession>> *)sessions withTouchAtPoint:(CGPoint)point;
// 将要向拖动会话中加入Item
- (void)dragInteraction:(UIDragInteraction *)interaction session:(id<UIDragSession>)session willAddItems:(NSArray<UIDragItem *> *)items forInteraction:(UIDragInteraction *)addingInteraction;

#pragma mark |拖动取消动画|
// 自定义取消拖动时的动画(取消拖动的动画开始前的回调)
- (nullable UITargetedDragPreview *)dragInteraction:(UIDragInteraction *)interaction previewForCancellingItem:(UIDragItem *)item withDefault:(UITargetedDragPreview *)defaultPreview;
// 取消动画将要开始
- (void)dragInteraction:(UIDragInteraction *)interaction item:(UIDragItem *)item willAnimateCancelWithAnimator:(id<UIDragAnimating>)animator;

@end





NS_ASSUME_NONNULL_END

#else
#import <UIKitCore/UIDragInteraction.h>
#endif

上一篇下一篇

猜你喜欢

热点阅读