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

  • 相关阅读:
    C# 如何保证对象线程内唯一:数据槽(CallContext)【转载】
    关于面试!(简历篇)
    以Windows服务方式运行ASP.NET Core程序【转载】
    .Net Core 项目在Windows服务中托管【转载】
    【转载】Ocelot网关的路由热更新
    Kafka的配置文件详细描述
    C#枚举中的位运算权限分配浅谈
    CSS 三角形
    Entity Framework 7 动态 DbContext 模型缓存 ModelCaching
    ASP.NET5 MVC6 利用Middleware 创建可访问HttpContext 的业务类工厂。(代替HttpContext.Current)
  • 原文地址:https://www.cnblogs.com/yinqiang/p/3491415.html
Copyright © 2011-2022 走看看