0

当我从服务器获得成功响应时,我想对按钮应用重力。我正在创建这样的 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 行为来启动。但什么也没有发生。我究竟做错了什么?

4

0 回答 0