Ios 使用Interface Builder时的UIKitDynamics
我想使用UIKitDynamics为一些按钮添加动画,但是使用uisnapbehavior进行非常基本的操作根本不起作用。我使用IB来布局我的所有子视图,所以请记住,我不能通过调用self.button.frame来重新定位任何内容,您必须使用约束 这就是我所拥有的…当我运行动画时,它会快速闪烁,看起来很糟糕Ios 使用Interface Builder时的UIKitDynamics,ios,objective-c,uiviewanimation,uikit-dynamics,Ios,Objective C,Uiviewanimation,Uikit Dynamics,我想使用UIKitDynamics为一些按钮添加动画,但是使用uisnapbehavior进行非常基本的操作根本不起作用。我使用IB来布局我的所有子视图,所以请记住,我不能通过调用self.button.frame来重新定位任何内容,您必须使用约束 这就是我所拥有的…当我运行动画时,它会快速闪烁,看起来很糟糕 // Position the buttons off screen self.swerveButton.translatesAutoresizingMaskIntoCon
// 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];
}];
}
UIKitDynamics不适用于约束。如果你想使用它们,你必须老一套地手动设置帧,至少在动画中是这样。我找到了一个解决办法,如果你创建一个自定义对象作为动态项,你可以在UISNAPBehavior的动作块中更改约束。效果很好。