使用Interface Builder时的UIKit Dynamics

时间:2014-08-06 16:41:52

标签: ios objective-c uiviewanimation uikit-dynamics

我想使用UIKitDynamics为一些按钮添加动画,但是使用UISnapBehaviour完成非常基本的操作根本不起作用。我使用IB来布局我的所有子视图,所以请记住,我无法通过调用self.button.frame重新定位任何内容,您必须使用约束。

这就是我所说的......当我运行动画时,它会快速闪烁并且看起来很糟糕。

// Position the buttons off screen
        self.swerveButton.translatesAutoresizingMaskIntoConstraints = NO;
        self.followButton.translatesAutoresizingMaskIntoConstraints = NO;
        self.swerveButtonTopSpaceConstraint.constant = -200;

        CGPoint swerveSnapPoint = self.swerveButton.center;
        CGPoint followSnapPoint = self.followButton.center;

        UISnapBehavior *followSnap = [[UISnapBehavior alloc] initWithItem:self.followButton
                                                              snapToPoint:followSnapPoint];

        UISnapBehavior *swerveSnap = [[UISnapBehavior alloc] initWithItem:self.swerveButton
                                                              snapToPoint:swerveSnapPoint];


        [self.overlayView fadeInWithDuration:0.2 completion:^{
            swerveSnap.damping = 0.3;
            [self.animator addBehavior:swerveSnap];

            followSnap.damping = 0.3;
            [self.animator addBehavior:followSnap];
        }];
    }

1 个答案:

答案 0 :(得分:0)

UIKitDynamics不适用于约束。如果你想使用它们,你必须手工上学并手动设置框架,至少在动画中是这样。