//
// UICollisionBehavior.h
// UIKit
//
// Copyright (c) 2012-2015 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, // items 相互碰撞两残,沒有指定碰撞的邊界
UICollisionBehaviorModeBoundaries = 1 << 1, // 指定了碰撞的邊界檐盟,沒有 items 的相互碰撞
UICollisionBehaviorModeEverything = NSUIntegerMax // 指定了碰撞邊界 和 items 的相互碰撞 (這個(gè)是默認(rèn)值)
} NS_ENUM_AVAILABLE_IOS(7_0);
// 碰撞行為的代理
@protocol UICollisionBehaviorDelegate <NSObject>
@optional
// 處理 items 之間的碰撞
- (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id <UIDynamicItem>)item1 withItem:(id <UIDynamicItem>)item2 atPoint:(CGPoint)p;
- (void)collisionBehavior:(UICollisionBehavior *)behavior endedContactForItem:(id <UIDynamicItem>)item1 withItem:(id <UIDynamicItem>)item2;
// items 和 boundary 之間的碰撞
// The identifier of a boundary created with translatesReferenceBoundsIntoBoundary or setTranslatesReferenceBoundsIntoBoundaryWithInsets is nil
// 通過 translatesReferenceBoundsIntoBoundary 和 setTranslatesReferenceBoundsIntoBoundaryWithInsets 創(chuàng)建的碰撞邊界的標(biāo)識(shí)是 nil
- (void)collisionBehavior:(UICollisionBehavior*)behavior beganContactForItem:(id <UIDynamicItem>)item withBoundaryIdentifier:(nullable id <NSCopying>)identifier atPoint:(CGPoint)p;
- (void)collisionBehavior:(UICollisionBehavior*)behavior endedContactForItem:(id <UIDynamicItem>)item withBoundaryIdentifier:(nullable id <NSCopying>)identifier;
@end
// 碰撞行為
NS_CLASS_AVAILABLE_IOS(7_0) @interface UICollisionBehavior : UIDynamicBehavior
// 通過一個(gè) items 數(shù)組來實(shí)例化一個(gè) 碰撞行為
- (instancetype)initWithItems:(NSArray<id <UIDynamicItem>> *)items NS_DESIGNATED_INITIALIZER;
// 在實(shí)例化碰撞行為對象后 添加 items
- (void)addItem:(id <UIDynamicItem>)item;
// 移除已經(jīng)存在的 items
- (void)removeItem:(id <UIDynamicItem>)item;
// 獲取所有的 items
@property (nonatomic, readonly, copy) NSArray<id <UIDynamicItem>> *items;
// 碰撞行為的模式 (默認(rèn)值 UICollisionBehaviorModeEverything )
@property (nonatomic, readwrite) UICollisionBehaviorMode collisionMode;
// 轉(zhuǎn)換 animator 引用的 View 的 bounds 作為碰撞的 bounds 爹耗。做的是一個(gè)簡單的 激活操作
@property (nonatomic, readwrite) BOOL translatesReferenceBoundsIntoBoundary;
// 轉(zhuǎn)換 animator 引用的 View 的 bounds 作為碰撞的 bounds , 并根據(jù) View 的 bounds 設(shè)置內(nèi)邊距朴爬。(和上面的屬性是一個(gè)效果峻呕,多了一個(gè)設(shè)置內(nèi)邊距的效果)
/*
使用這個(gè)方法會(huì)產(chǎn)生的影響:
1. animator 引用的 View 的 bounds, 碰撞范圍是引用 view 的 bounds。
2. animator 引用的 collection view 的 bounds, collection view layout 的引用的 bounds
3. 引用的 item 的時(shí)候,是沒有碰撞邊距的若贮。
*/
- (void)setTranslatesReferenceBoundsIntoBoundaryWithInsets:(UIEdgeInsets)insets;
// 通過指定一個(gè)貝塞爾路徑的方式來添加碰撞邊界
/*
* * identifier: 碰撞邊界的范圍省有。
* * bezierPath: 碰撞邊界的路徑
* 路徑的原點(diǎn)和坐標(biāo)系依靠的是實(shí)例化的 animator
*/
- (void)addBoundaryWithIdentifier:(id <NSCopying>)identifier forPath:(UIBezierPath *)bezierPath;
// 通過兩個(gè)點(diǎn)來確定碰撞邊界 (這是一個(gè)方便的方法基于addBoundaryWithIdentifier:forPath:方法痒留。)
/*
* * fromPoint : 開始的點(diǎn)
* * toPoint : 結(jié)束點(diǎn)
*/
- (void)addBoundaryWithIdentifier:(id <NSCopying>)identifier fromPoint:(CGPoint)p1 toPoint:(CGPoint)p2;
// 通過一個(gè) 標(biāo)識(shí)來獲取邊界的貝塞爾路徑
- (nullable UIBezierPath *)boundaryWithIdentifier:(id <NSCopying>)identifier;
// 通過標(biāo)識(shí)來移除貝塞爾路徑
- (void)removeBoundaryWithIdentifier:(id <NSCopying>)identifier;
// 獲取所有的碰撞路徑的標(biāo)識(shí)
@property (nullable, nonatomic, readonly, copy) NSArray<id <NSCopying>> *boundaryIdentifiers;
// 移除所有的碰撞路徑
- (void)removeAllBoundaries;
// 碰撞路徑的代理
@property (nullable, nonatomic, weak, readwrite) id <UICollisionBehaviorDelegate> collisionDelegate;
@end
NS_ASSUME_NONNULL_END
UICollisionBehavior
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來匈子,“玉大人河胎,你說我怎么就攤上這事』⒍兀” “怎么了游岳?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長其徙。 經(jīng)常有香客問我胚迫,道長,這世上最難降的妖魔是什么唾那? 我笑而不...
- 正文 為了忘掉前任访锻,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘朗若。我一直安慰自己恼五,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布哭懈。 她就那樣靜靜地躺著灾馒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪遣总。 梳的紋絲不亂的頭發(fā)上睬罗,一...
- 文/蒼蘭香墨 我猛地睜開眼菇爪,長吁一口氣:“原來是場噩夢啊……” “哼算芯!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起凳宙,我...
- 序言:老撾萬榮一對情侶失蹤熙揍,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后氏涩,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體届囚,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年是尖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了意系。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站弦疮,受9級特大地震影響夹攒,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜胁塞,卻給世界環(huán)境...
- 文/蒙蒙 一咏尝、第九天 我趴在偏房一處隱蔽的房頂上張望压语。 院中可真熱鬧,春花似錦编检、人聲如沸胎食。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽厕怜。三九已至,卻和暖如春蕾总,著一層夾襖步出監(jiān)牢的瞬間粥航,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓蚀浆,卻偏偏與公主長得像缀程,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子市俊,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 賽瑪新品按摩椅1003Q-2秕衙,京東眾籌隆重發(fā)布啦蠢甲!僅需1元僵刮,僅需1元据忘,僅需1元錢!搞糕!將可獲預(yù)售價(jià)為6500元的賽瑪...
- 聽課和拿筆真是兩回事勇吊。 我會(huì)按時(shí)跟課。但每次要做作業(yè)的時(shí)候就各種心理斗爭窍仰,然后拖延汉规。 報(bào)這些繪畫訓(xùn)練營其實(shí)是想重走...