zoukankan      html  css  js  c++  java
  • UIDynamic


    一.使用步骤
    1.创建仿真者
    UIDynamicAnimator *animaytor = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];//后面的参数是:参照哪个View
    2.添加要仿真的动作或者行为
    UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[redView,blueView]];
    //添加碰撞检测行为
    UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[redView,blueView]];
    3.将动作添加到仿真者中
    [animaytor addBehavior:collision];
    collision.translatesReferenceBoundsIntoBoundary = YES;
    将动作添加到仿真者中
    [animaytor addBehavior:gravity];
    _animator = animaytor;//必须定义一个成员变量保存住仿真者,否则出了这个方法仿真者就不存在了

    ============================================================================
    1.添加吸附动作 UISnapBehavior ------->吸附动作必须清除仿真者之前的行为
    UISnapBehavior *snap = [[UISnapBehavior alloc] initWithItem:self.box snapToPoint:location];//location是目标点
    [self.animator addBehavior:snap];
    2.推动作 UIPushBehavior
    1>推行为必须设置3个属性 --->偏移量 //计算偏移量CGPoint offset = CGPointMake(_FristPoint.x - endPoint.x, _FristPoint.y - endPoint.y);
    1)距离 也就是推行为的距离 --->按下屏幕的x,y -离开屏幕的x,y是偏移量,然后再用偏移量的(x*x+y*y)在开方,就是要求的距离,具体参考三角形求斜边公式
    2)角度 ----->CGFloat angle = atan2f(offSet.y, offSet.x)
    3) _push.active = YES;
    3.刚性动作
    1> 刚性行为初始化的时候需要指定2个点
    1)定位点
    2)锚点
    4.弹性刚性行为----->和刚性动作大部分一样
    多两个属性要设置
    1)damping 振幅
    2)frequency 频率
    5.碰撞检测 ---->UICollisionBehavior
    UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[blueView]];
    Boundary是即参与碰撞,又不会发生位移的静态物体的边界
    [collision addBoundaryWithIdentifier:@"lalala" fromPoint:redView.frame.origin toPoint:CGPointMake(toX, toY)];
    #pragma mark - 碰撞的代理方法
    - (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier atPoint:(CGPoint)p

  • 相关阅读:
    201771010101 白玛次仁 《2018面向对象程序设计(Java)》第七周学习总结
    201771010101 白玛次仁 《2018面向对象程序设计(Java)课程学习进度条》
    实验六201771010101 白玛次仁
    第七周作业
    第七周上机练习
    第六周作业
    第六周上机练习
    第五周上机作业
    Java第四周作业
    Java第四次作业
  • 原文地址:https://www.cnblogs.com/yinqiang/p/3491415.html
Copyright © 2011-2022 走看看