15.UIDynamic 物理引擎

    1. UIDynamic 是物理引擎, 模仿物理效果
    2. 知名2D物理引擎 Box2d Chipmunk
    3. 只有遵守了UIDynamicItem协议的对象

    UIVIew默认遵守了协议

    UICollectionViewLayouetAttributes已经遵循了

    1. 重力行为

    UIGravityBehavior    重力行为

    UICollisionBehavior 碰撞行为

     

     

    1. UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];

    UIGravityBehavior  *grivity = [[UIGravityBehavior alloc] initWithItems:@[self.myView];

    grivity.gravityDirection = CGVectorMake( ,);

    grivity.angle = 0; 弧度方向  跟上面的设置有矛盾, 哪个在下面哪个起作用M_PI_2

    grivity.magnitude = 1;  设置重力加速度   gravityDiretion 有矛盾

    [animator addBehavior:grivity];

     

    1. 弹性行为UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:--];

    collision.translatesRefrernceBoundsIntoBoundary = YES;

    [self.animator addBehavior:collision];

    UIDynamicItemBehavior *item = UIDynamicItemBehavior alloc] initWithItems:@[self.myView]];辅助行为

    item.resistance = 1; 阻力

    item.elasticity = 0.5; 弹性系数

     

    1. 通常用辅助行为来设置弹性系数

    只要是行为就要添加

    1. [collision addBoundaryWithIdentifier:@"c1" fromePoint:CGPointMake   toPoint;自定义一条线为边界
    2. UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(20, 300, 400, 150)];

    [collision addBoundaryWithIdentifier:@"c2" forPath:path];

     

    1. 检测碰到的是哪一根线  设置代理<UICollisionDelegate>

    collision.collisionDelegate = self;

    • (void)collisionBehavior -------withBoundaryIdentifier 当碰撞的时候就会调用

    beganContactForItem:标示碰撞的物体

    identifier:标示边界的标示符

    atPoint:标示碰撞的点

     

    UIView *view = (UIView*) item; 要强转

     

    1. 碰撞模式

    collision.collisionMode = UICollisionBehaviiorModeItems;  只和物体碰撞

    Boundaries只和边界碰撞

    everything 都碰撞

     

    1. item.allowsrotation = YES  是否旋转 
    2. 捕捉行为  UISnapBehavior *snap = [[UISnapBehavior alloc]initWithItem:self.myView snapToPoint:CGPoint];   比如移动到手指所触摸的点

    阻力系数 snap.damping = 0.5;  取值范围是0.5~1;  默认应该是0.5

     

    1. 附着行为  需要重力行为 initWIthitem:标示产生附着行为的物体 attachedToAnchor:附着的点  没有重力行为附着行为没效果

    UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:self.myView attachedToAnchor:point];

     

    1. 只要重力行为有效果,就会调用 [ ---  setAction:^{  可以在这个方法中划线 }];
    2. 自定义了viewCZView  在控制器要获取相应的定义的变量 要强转CZView = (CZView *)self.view;
    3. attachiment.damping = 0.5  阻尼系数

    attachiment.frequency = 0.5 频率

    attachiment.length  是附着点和中心点得距离

    1. 中心点偏移的改变

    UIAttachmentBehavior *attachment = [[UIAttachmentbehavior alloc] initWithItem:@[self.myView] offsetFromCenter:UIOffset attachedToAnchor:CGPoint];

     

    1.  推力行为[self.view converPoint:(CGPoint) fromView:(UIView*)];  fromView中的点坐标转换成self.view的点坐标。
    2. UIPushBehavior *push = [[UIPushBehavior alloc] initWithItems:@[] mode:UIPushBehaviorMode Continuous];  Insantaneous   一次性会回去

    触摸点  物体的中心点进行计算  加速度 方向

    方向  push.pushDirection = CGVectorMake(pushX, pushY);

    加速度  push.magnitude = sqrt();

     

    1. [NSURL fileURLWithPath:] 本地资源

    [NSURL urlWith:http://] 网络资源

     

    1. 改变原来附着点得锚点就可以移动原来的画面了

    self.attachment.anchorPoint = point;

     

    1. 移除附着点

    [self.animator remove ----];

     

    1. 自定义layer  中要创建layer  用的方法是-(void)drawInContext:(CGContextRef)ctx{};

    记住 在自定义中的地方 要重绘。[layer setNeedsDisplay]  view也有这个方法

    代理或者继承都要重绘

     

    1. 通过代理方法也可以在控制器中进行绘制图形  创建layer

     

    1. keyAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];中间快 两边慢
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值