6
我正在學習iOS開發。當我添加矩形視圖並希望受重力影響時,構建並運行我的測試應用程序,我發現它沒有重力。 這是viewDidLoad中的代碼在我viewController.m:爲什麼UIKit Dynamics不起作用?
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *squre = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
squre.backgroundColor = [UIColor grayColor];
[self.view addSubview:squre];
UIDynamicAnimator *_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UIGravityBehavior *_gravity = [[UIGravityBehavior alloc] initWithItems:@[squre]];
[_animator addBehavior:_gravity];
噢,謝謝〜 – 2014-11-24 02:03:47