Q:

UIGravityBehavior isn't working

I'm trying to learn UIKit Dynamics.
I have created a box view and added the UIGravityBehavior on it, but nothing happens when I run the Project!
Viewcontroller.m
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView* box = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 100, 100)];
    box.backgroundColor = [UIColor blackColor];
    [self.view addSubview:box];
    UIGravityBehavior* gravityBehaviour = [[UIGravityBehavior alloc]init];
    [gravityBehaviour addItem:box];
    UIDynamicAnimator* myAnimator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
    [myAnimator addBehavior:gravityBehaviour];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

This is my view controller.m file.
What is wrong in the program?

A:

If you want to use it in ViewDidLoad, you need to announce UIDynamicAnimator and UIGravityBehavior as properties of the current VC. The Automatic Reference Counting will deallocate those objects after ViewDidLoad finishing.
Regards

