導(dǎo)語
捕獲行為是定義一個(gè)動(dòng)態(tài)元素運(yùn)動(dòng)到指定點(diǎn),運(yùn)動(dòng)過程伴隨彈簧效果。
構(gòu)造
UISnapBehavior * snapBehavior =
[[UISnapBehavior alloc] initWithItem:_dynamicItem1View snapToPoint:CGPointMake(250, 400)];
- (instancetype)initWithItem:(id <UIDynamicItem>)item snapToPoint:(CGPoint)point NS_DESIGNATED_INITIALIZER;
上面方法為指定構(gòu)造方法,items參數(shù)為添加的動(dòng)態(tài)元素,point
參數(shù)為要捕獲的點(diǎn)。

屬性
- 捕獲點(diǎn)
@property (nonatomic, assign) CGPoint snapPoint NS_AVAILABLE_IOS(9_0);
該屬性的默認(rèn)值為initWithItem:snapToPoint:方法設(shè)置的值,當(dāng)該屬性的值發(fā)生改變時(shí),捕獲行為會(huì)更新,動(dòng)態(tài)元素會(huì)向新的捕獲點(diǎn)捕獲。
我們將點(diǎn)擊手勢(shì)的位置設(shè)置為捕獲行為的捕獲點(diǎn)
-(void)click:(UITapGestureRecognizer *)gesture{
CGPoint point = [gesture locationInView:referenceView];
_snapBehavior.snapPoint = point;
}
看一下效果:

- 震動(dòng)阻尼
@property (nonatomic, assign) CGFloat damping;
阻尼的有效范圍為0.0~1.0,0.0最大震蕩、1.0最小震蕩,默認(rèn)值為0.5

藍(lán)球的阻尼為
0.0黑球的阻尼為
1.0
版權(quán)聲明:出自MajorLMJ技術(shù)博客的原創(chuàng)作品 ,轉(zhuǎn)載時(shí)必須注明出處及相應(yīng)鏈接!