当我从服务器获得成功响应时,我想将重力应用于按钮。我正在创建像这样的UIKitDynamics元素:
-(void) setup
{
_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
_gravity = [[UIGravityBehavior alloc] initWithItems:@[self.saveShareButton]];
_collision = [[UICollisionBehavior alloc] initWithItems:@[self.saveShareButton]];
_collision.translatesReferenceBoundsIntoBoundary = YES;
_push = [[UIPushBehavior alloc] initWithItems:@[self.saveShareButton] mode:UIPushBehaviorModeInstantaneous];
[_push setPushDirection:CGVectorMake(0, 1)];
[_animator addBehavior:_collision];
[_animator addBehavior:_gravity];
}
这是网络服务代码
-
(IBAction) saveStory
{
Story *story = [[Story alloc] init];
story.title = self.titleTextField.text;
story.abstract = self.abstractTextView.text;
[[StoryHTTPClient sharedClient] createStory:story success:^(NSURLSessionDataTask *task, id responseObject) {
// success
[_animator addBehavior:_gravity];
[_animator addBehavior:_push]; // apply push to that gravity will kick off
} failure:^(NSURLSessionDataTask *task, NSError *error) {
// failure
}];
}
我在成功块中添加_gravity行为,然后我应用_push行为来启动。但没有任何反应。我做错了什么?