动画行为

   1. 创建仿真者 ReferenceView: 仿真区域 ( 参考系 )
    self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
     2. 创建仿真行为  重力行为
     UIGravityBehavior * gravity = [[UIGravityBehavior alloc] initWithItems:@[self.redView]];
     2.1 设置重力方向
    方式一 ( 包括方向 和大小 )
    gravity.gravityDirection = CGVectorMake(10, 10);
   方式二
    设置方向
    gravity.
angle = M_PI_4 ;
     设置大小   1000 points/second²
    gravity. magnitude = 10 ;
     3. 把仿真行为添加到仿真者中
     [self.animator addBehavior:gravity];

    2. 创建仿真行为 ( 碰撞行为 )
   
UICollisionBehavior * collision = [[ UICollisionBehavior alloc ] initWithItems : @[ self . redView ] ];
     设置 YES 就是把仿真区域转化为碰撞的边界
    collision.translatesReferenceBoundsIntoBoundary = YES;

     弹性系数 (0 ---- 1)
    item.elasticity = 0;


   2. 创建仿真行为 ( 吸附 )
   
UISnapBehavior * snap = [[ UISnapBehavior alloc ] initWithItem : self . redView snapToPoint :locP];
       阻尼系数 (0 --- 1) 0: 最抖动   1: 最不抖动
    snap.damping = 0;

 
附着行为   
    - (instancetype)initWithItem:(id <UIDynamicItem>)item attachedToAnchor:(CGPoint)point;
    元素附着到点
   
   - (instancetype)initWithItem:(id <UIDynamicItem>)item offsetFromCenter:(UIOffset)offset attachedToAnchor:(CGPoint)point NS_DESIGNATED_INITIALIZER;
    元素附着到指定点 ( 根据 center 偏移 )
   
    - (instancetype)initWithItem:(id <UIDynamicItem>)item1 attachedToItem:(id <UIDynamicItem>)item2;
    元素之间的附着
   
    - (instancetype)initWithItem:(id <UIDynamicItem>)item1 offsetFromCenter:(UIOffset)offset1 attachedToItem:(id <UIDynamicItem>)item2 offsetFromCenter:(UIOffset)offset2 NS_DESIGNATED_INITIALIZER;
  指定元素之间的附着点 ( 根据每个元素的 center 偏移 )
   
    2. 创建仿真行为 ( 附着行为 )
    UIAttachmentBehavior * attachment = [[UIAttachmentBehavior alloc] initWithItem:self.redView attachedToAnchor:locP];
   
          获取红色 View size
    CGSize reSize = self . redView . bounds . size ;
   
    UIAttachmentBehaviorTypeItems, 元素之间的附着
    UIAttachmentBehaviorTypeAnchor 元素和点的附着
   
   
附着行为  (刚性附着  弹性附着)
   
UIAttachmentBehavior * attachment = [[ UIAttachmentBehavior alloc ] initWithItem : self . redView offsetFromCenter : UIOffsetMake (-reSize. width / 2 , -reSize. height / 2 ) attachedToAnchor :locP];
   
设置线长
    attachment.length = 100;
   
   
CZView * view = ( CZView *) self . view ;
   
设置起点和终点
    attachment.
action = ^{
       
设置起点
        view.
startPoint = locP;
       
设置终点
        view.endPoint = self.redView.center;
       
转换坐标点
        view.
endPoint = [ self . view convertPoint : CGPointZero fromView : self . redView ];
    };
   
   设置弹性附着 ( 同时设置以下两个属性 )
   
频率
    attachment.
frequency = 0.5 ;
   
阻尼系数
    attachment.damping = 0.5;
     

    2. 创建仿真行为  平推
      UIPushBehaviorModeContinuous,     持续
      UIPushBehaviorModeInstantaneous   瞬时   一次性
UIPushBehavior * push = [[ UIPushBehavior alloc] initWithItems: @[ self. redView ] mode: UIPushBehaviorModeInstantaneous];
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值