美文网首页< UIKit >
UICollisionBehavior.h

UICollisionBehavior.h

作者: zhYx_ | 来源:发表于2019-06-17 18:02 被阅读0次
    
    #if USE_UIKIT_PUBLIC_HEADERS || !__has_include(<UIKitCore/UICollisionBehavior.h>)
    //
    //  UICollisionBehavior.h
    //  UIKit
    //
    //  Copyright (c) 2012-2018 Apple Inc. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import <UIKit/UIView.h>
    #import <UIKit/UIBezierPath.h>
    #import <UIKit/UIDynamicBehavior.h>
    
    NS_ASSUME_NONNULL_BEGIN
    
    @class UICollisionBehavior;
    
    
    
    /* 碰撞类型 <枚举> */
    typedef NS_OPTIONS(NSUInteger, UICollisionBehaviorMode) {
        UICollisionBehaviorModeItems        = 1 << 0,       /// Item之间的碰撞
        UICollisionBehaviorModeBoundaries   = 1 << 1,       /// 边界碰撞
        UICollisionBehaviorModeEverything   = NSUIntegerMax /// 碰撞所有
    } NS_ENUM_AVAILABLE_IOS(7_0);
    
    
    
    ///!!!: 碰撞行为代理 <协议>
    @protocol UICollisionBehaviorDelegate <NSObject>
    
    @optional
    // 两个Item开始碰撞时的回调
    - (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id <UIDynamicItem>)item1 withItem:(id <UIDynamicItem>)item2 atPoint:(CGPoint)p;
    // 两个Item结束碰撞时的回调
    - (void)collisionBehavior:(UICollisionBehavior *)behavior endedContactForItem:(id <UIDynamicItem>)item1 withItem:(id <UIDynamicItem>)item2;
    
    // Item和碰撞边界开始碰撞时的回调
    - (void)collisionBehavior:(UICollisionBehavior*)behavior beganContactForItem:(id <UIDynamicItem>)item withBoundaryIdentifier:(nullable id <NSCopying>)identifier atPoint:(CGPoint)p;
    // Item和碰撞边界结束碰撞时的回调
    - (void)collisionBehavior:(UICollisionBehavior*)behavior endedContactForItem:(id <UIDynamicItem>)item withBoundaryIdentifier:(nullable id <NSCopying>)identifier;
    
    @end
    
    
    
    
    
    #pragma mark - 碰撞行为 Class
    #pragma mark -
    NS_CLASS_AVAILABLE_IOS(7_0) @interface UICollisionBehavior : UIDynamicBehavior
    
    /* 实例化 */
    - (instancetype)initWithItems:(NSArray<id <UIDynamicItem>> *)items NS_DESIGNATED_INITIALIZER;
    
    // 添加碰撞Item
    - (void)addItem:(id <UIDynamicItem>)item;
    // 移除碰撞Item
    - (void)removeItem:(id <UIDynamicItem>)item;
    
    /// 已添加到碰撞行为的Item
    @property (nonatomic, readonly, copy) NSArray<id <UIDynamicItem>> *items;
    /// 碰撞类型
    @property (nonatomic, readwrite) UICollisionBehaviorMode collisionMode;
    /// 是否开启系统碰撞边界(即手机屏幕的边界;碰撞标识符为nil;如果collisionMode是UICollisionBehaviorModeItems类型,此效果无效)
    @property (nonatomic, readwrite) BOOL translatesReferenceBoundsIntoBoundary;
    // 设置自定义碰撞边界(碰撞标识符为nil)
    - (void)setTranslatesReferenceBoundsIntoBoundaryWithInsets:(UIEdgeInsets)insets;
    
    // 添加碰撞边界(设置贝塞尔曲线路径为边界)
    - (void)addBoundaryWithIdentifier:(id <NSCopying>)identifier forPath:(UIBezierPath *)bezierPath;
    // 添加碰撞边界(设置两点之间的线段为边界)
    - (void)addBoundaryWithIdentifier:(id <NSCopying>)identifier fromPoint:(CGPoint)p1 toPoint:(CGPoint)p2;
    // 返回指定标识符的贝塞尔边界
    - (nullable UIBezierPath *)boundaryWithIdentifier:(id <NSCopying>)identifier;
    // 移除指定标识符的碰撞边界
    - (void)removeBoundaryWithIdentifier:(id <NSCopying>)identifier;
    
    /// 获取已经添加到碰撞边界的标识符
    @property (nullable, nonatomic, readonly, copy) NSArray<id <NSCopying>> *boundaryIdentifiers;
    
    // 移除所有碰撞边界
    - (void)removeAllBoundaries;
    
    /// 碰撞行为代理
    @property (nullable, nonatomic, weak, readwrite) id <UICollisionBehaviorDelegate> collisionDelegate;
    
    @end
    
    
    
    
    
    NS_ASSUME_NONNULL_END
    
    #else
    #import <UIKitCore/UICollisionBehavior.h>
    #endif
    
    

    相关文章

      网友评论

        本文标题:UICollisionBehavior.h

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