Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Junaid Abd
Courses Plus Student 32 PointsCreate 'gravity' that affect buttons?
How do I create 'gravity' in my all so when a button is pressed the rest of the buttons will fall to the bottom if the screen. Also how can I have one or two buttons which are immune to this?
Language- Swift
David Marinez
2,610 PointsDavid Marinez
2,610 PointsYou can add "UIGravityBehavior" to all buttons you want to fall. If you want them to have collision with the screen you need to add "UICollisionBehavior". You can do something like this:
@interface yourClass() @property (strong, nonatomic) UIDynamicAnimator *animator; @end
-(void) animateButton: (UIButton *) button toFall: (BOOL) fallingDown withMagnitud: (CGFloat) magnitude { [self.animator removeAllBehaviors];
}