美文网首页
仿真动画

仿真动画

作者: LucXion | 来源:发表于2017-09-14 16:09 被阅读0次

    标签:弹性附着行为、刚性附着行为、碰撞边缘检测、推动行为、吸附行为、重力行为
    1 重力行为

    -(void)重力行为UIGravityBehavior{
    //在当前View中强引用动画者属性,创建动 画者(动力学元素 和 iOS物理引擎的中介),参考对象参数表示在谁里面开启了这个环境(这个环境是没有范围的).
        self.dynamicAnimator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view]; 
    //根据动力学元素创建行为,参数是一个数组
        UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc]initWithItems:@[self.greenView]];
    //将行为添加到动画者身上
        [self.dynamicAnimator addBehavior:gravityBehavior];
    }
    

    2 碰撞边缘检测

    -(void)碰撞边缘检测UICollisionBehavior{
        //在开启动画者前提下
       //创建行为
        UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc]initWithItems:@[self.greenView]];
    //注意开启碰撞边缘检测    
        collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
    //将边缘检测添加到动画者
        [self.dynamicAnimator addBehavior:collisionBehavior];
    }
    

    3 吸附行为

    -(void)吸附行为UISnapBehavior{
    //吸附行为自带一个类似刹车的效果
    //如果要进行连续多次的吸附行为,每一次开头都必须清除上一次的吸附行为
        [self.dynamicAnimator removeBehavior:self.snapBehavior];
    //动力学对象的中心点将移动到该指定的点中
        UISnapBehavior *snapBehavior = [[UISnapBehavior alloc]initWithItem:self.greenView snapToPoint:CGPointMake(1, 1)]; 
        [self.dynamicAnimator addBehavior:snapBehavior];
        self.snapBehavior = snapBehavior;
    }
    

    4 推动行为

    -(void)推动行为UIPushBehavior{
        UIPushBehavior *pushBehavior = [[UIPushBehavior alloc]initWithItems:@[self.greenView] mode:UIPushBehaviorModeInstantaneous];
        //角度  三角形锐角 : tan(相对直角边,相邻直角边)  sin(相对直角边,相邻斜边)
        pushBehavior.angle = 0;
      //力度
        pushBehavior.magnitude = 10;
        [self.dynamicAnimator addBehavior:pushBehavior];
    }
    

    5 刚性附着行为

    -(void)刚性附着行为UIAttachmentBehavior{
    //刚性附着行为的创建方法有很多,这里设置的点只是确定动作力元素(默认是当前位置的中心点)与附着点的距离.
        //offer : 偏离中心点的距离
        //两个元素,元素与元素的附着
        UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc]initWithItem:self.greenView attachedToAnchor:CGPointMake(9, 9)];
       //通过附着点位置的更改,使动作力元素的位置改变,距离确定,方向却不一定相同
        attachmentBehavior.anchorPoint = CGPointMake(1, 1);
    }
    

    6 弹性附着行为

    -(void)弹性附着行为UIAttachmentBehavior{
    //在刚性附着行为上增加设置两个属性
        /*
         开启晃动
         self.myAttach.damping = 1.0;
         频率
         self.myAttach.frequency = 0.8;
         //注意,要在对象重力行为下才会晃动(或者说拖拽中?)
         */
    }
    

    相关文章

      网友评论

          本文标题:仿真动画

          本文链接:https://www.haomeiwen.com/subject/rxpdsxtx.html