How to set a different vector of gravity for different objects of gravitational behavior?

I have two UIViews.i want to set different gravitydirection vector for these two views for making **attraction**.and i am doing this by having two gravitybehavior but when i am adding these two to animator.
it not working as **attracting** to each other.
also giving warning like :-Multiple gravity behavior per animator is undefined and may assert in the future.
Below is the code i am using to make Attractiuon effect b/w two views.


gravity behavior - make an animation of gravity. Animator is a dynamic animator.

UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[v1]];

      CGVector vector = CGVectorMake(1.0, 1.0);

    [gravityBehavior setGravityDirection:vector];

    UIGravityBehavior *gravityBehavior1 = [[UIGravityBehavior alloc] initWithItems:@[v2]];
        CGVector vector1 = CGVectorMake(-1.0, -1.0);

    [gravityBehavior1 setGravityDirection:vector1];

       self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    [self.animator addBehavior:gravityBehavior];
     [self.animator addBehavior:gravityBehavior1];


Please, help! Thanks for the help!


source to share

All Articles