1.3物理仿真器(動畫者)
(一)物理仿真器的作用
作用:可以讓物理仿真元素執(zhí)行物理仿真行為,是UIDynamicAnimator類的對象.
(二)常用屬性和方法
常用屬性
// 參照視圖
@property (nullable, nonatomic, readonly) UIView *referenceView;
// 所有添加到仿真器上的動力學(xué)行為
@property (nonatomic, readonly, copy) NSArray<UIDynamicBehavior*> *behaviors;
// 是否正在進(jìn)行物理仿真
@property (nonatomic, readonly, getter = isRunning) BOOL running;
// 代理對象,監(jiān)聽物理仿真器的仿真過程(比如,仿真開始仿真結(jié)束)
@property (nullable, nonatomic, weak) id <UIDynamicAnimatorDelegate> delegate;
常用方法
// 初始化一個仿真器,view是參考的視圖,表示物理仿真的范圍.
- (instancetype)initWithReferenceView:(UIView *)view ;
// 添加仿真行為到仿真器
- (void)addBehavior:(UIDynamicBehavior *)behavior;
// 移除一個指定的仿真行為
- (void)removeBehavior:(UIDynamicBehavior *)behavior;
// 移除該仿真器上面的所有仿真行為
- (void)removeAllBehaviors;
注意:一般使用strong修飾仿真器
// 仿真器(動畫者)對象
@property (nonatomic, strong) UIDynamicAnimator *animator;
// 創(chuàng)建動畫者對象并且作用范圍為當(dāng)前控制器view
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];