1

我在调试器中收到“每个动画师的多重重力行为未定义,将来可能会断言”。我认为这是因为我使用自定义 [SASlideMenu 视图控制器] ( https://github.com/stefanoa/SASlideMenu )。它是什么?

4

1 回答 1

1

查找UIGravityBehavior创建对象并将其添加到UIDynamicAnimator实例的代码。似乎行为正在动画师中累积(并且在完成动作时没有被释放)。

这个项目有同样的问题https://github.com/simonwhitaker/ioscon-2014-demo。可以使用以下方法解决- (void)removeBehavior:(UIDynamicBehavior *)behavior

- (IBAction)dismissAlertView:(id)sender {
    UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.alertView]];

    gravity.magnitude = 4;
    __weak __typeof(self) weakSelf = self;
    __weak __typeof__(gravity) weakGravity = gravity;

    gravity.action = ^{
        __strong __typeof(weakSelf) strongSelf = weakSelf;
        if (!CGRectIntersectsRect(strongSelf.alertView.frame, strongSelf.alertBackgroundView.bounds)) {

            //[strongSelf.animator removeAllBehaviors];
            [strongSelf.animator removeBehavior:weakGravity];

            [UIView animateWithDuration:0.1 animations:^{
                strongSelf.alertBackgroundView.alpha = 0.0;
            }];
        }
    };

    [self.animator addBehavior:gravity];
}
于 2014-05-27T22:39:26.627 回答