动画行为

来源:互联网 发布:淘宝上有纯粮食酒吗 编辑:程序博客网 时间:2024/06/05 19:04
   1.创建仿真者ReferenceView:仿真区域(参考系)
   self.animator = [[UIDynamicAnimatoralloc] initWithReferenceView:self.view];
    2.创建仿真行为  重力行为
    UIGravityBehavior * gravity = [[UIGravityBehavioralloc] initWithItems:@[self.redView]];
    2.1设置重力方向
   方式一 (包括方向和大小)
    gravity.gravityDirection = CGVectorMake(10, 10);
  方式二
   设置方向
    gravity.
angle= M_PI_4;
    设置大小  1000 points/second²
    gravity.magnitude= 10;
    3.把仿真行为添加到仿真者中
    [self.animatoraddBehavior:gravity];

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

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


   2.创建仿真行为(吸附)
   
UISnapBehavior* snap = [[UISnapBehavioralloc]initWithItem:self.redViewsnapToPoint: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];
   
          获取红色Viewsize
   CGSize reSize = self.redView.bounds.size;
   
    UIAttachmentBehaviorTypeItems,元素之间的附着
    UIAttachmentBehaviorTypeAnchor元素和点的附着
   
   
附着行为  (刚性附着 弹性附着)
   
UIAttachmentBehavior* attachment = [[UIAttachmentBehavioralloc]initWithItem:self.redViewoffsetFromCenter: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.viewconvertPoint:CGPointZerofromView:self.redView];
    };
   
  设置弹性附着 (同时设置以下两个属性)
   
频率
    attachment.
frequency= 0.5;
   
阻尼系数
    attachment.damping =0.5;
    

    2.创建仿真行为  平推
      UIPushBehaviorModeContinuous,    持续
      UIPushBehaviorModeInstantaneous  瞬时 一次性
UIPushBehavior * push = [[UIPushBehavioralloc] initWithItems:@[self.redView]mode:UIPushBehaviorModeInstantaneous];
0 0
原创粉丝点击