Is there any way to attract two masses to each other as if in free space using UIKit Dynamics?
I know by default the gravity behaviour acts as if the gravity is pointing down to the earth. But this seems only useful for a small class of behaviours. The only way I can think of doing this is by giving the two items huge mass and no initial gravity vector (but applying the UIGravityBehavior
to them, errrr adding them to the UIGravityBehavior
? hah).
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
//first item with heavy mass.
self.dynamic = [[UIDynamicItemBehavior alloc] initWithItems:@[self.heavyCircle]];
self.dynamic.density = 1000000000;
self.gravity = [[UIGravityBehavior alloc] initWithItems:@[self.heavyCircle]];
self.gravity.gravityDirection = CGVectorMake(0, 0);
[self.animator addBehavior:self.gravity];
[self.animator addBehavior:self.dynamic];
//second item with less mass
self.dynamic = [[UIDynamicItemBehavior alloc] initWithItems:@[self.smallCircle]];
self.dynamic.density = 10;
//also tried with a huge value here as well.
//HUGE_VALF seems to make the app choke
self.gravity = [[UIGravityBehavior alloc] initWithItems:@[self.smallCircle]];
self.gravity.gravityDirection = CGVectorMake(0, 0);
[self.animator addBehavior:self.gravity];
[self.animator addBehavior:self.dynamic];
But this doesn't do anything at all. :/ I was all excited about the physics in UIKit Dynamics and I'm hoping this type of behaviour is possible.
If this is not possible with UIKit Dynamics, is there another way that is equally integrated (retaining interactivity, and functions as a UIView
/Button
/Whatever)? Sprite Kit?
Thanks for any help!