对于动画UIDynamicAnimator的学习

正在第一步学习,看了一些其他人的博客,自己看了一下文档,这个类很简单,没有想象的难,但是可以写出漂亮的动画:

1.没有初步整理,附上一些方法,随后写出一个Demo

 UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 100, 100)];

    aView.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:aView];

    aView.transform = CGAffineTransformRotate(aView.transform, 45);

    //重力作用

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

    UIGravityBehavior *beah = [[UIGravityBehavior alloc]initWithItems:@[aView]];

    

    self.beah = beah;

    [anmimaor addBehavior:beah];

    

    

    

    

    

    

    //碰撞作用

    UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc]initWithItems:@[aView]];

    collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;

    [anmimaor addBehavior:collisionBehavior];

    self.collisionBehavior = collisionBehavior;

    collisionBehavior.collisionDelegate = self;

    

    //链接锚点

//    UIAttachmentBehavior *attachmentBeah = [[UIAttachmentBehavior alloc]initWithItem:aView attachedToAnchor:CGPointMake(300, 400)];

//    [anmimaor addBehavior:attachmentBeah];

    

    

    

    UIPushBehavior *ppushBeah = [[UIPushBehavior alloc]initWithItems:@[aView] mode:UIPushBehaviorModeContinuous];

    ppushBeah.pushDirection = CGVectorMake(10, 19);

    [anmimaor addBehavior:ppushBeah];

    

    

 

    //这个是吸附作用

//    UISnapBehavior *snapBeah = [[UISnapBehavior alloc]initWithItem:aView snapToPoint:CGPointMake(10, 20)];

//    snapBeah.damping = 20;

//    

//    [anmimaor addBehavior:snapBeah];

    

    self.Animator = anmimaor;

 

 

//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

//       

//        [aView removeFromSuperview];

//        

//    });

原文地址:https://www.cnblogs.com/runningsoul/p/4877575.html