我正在尝试学习 UIKit Dynamics。
我创建了一个框视图并在其上添加了 UIGravityBehavior,但是当我运行项目时没有任何反应!
视图控制器.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
这是我的视图 controller.m 文件。
程序有什么问题?