我在MonoMac中工作,并试图在按钮单击时动态控制动态控件的宽度和高度约束。阅读以下页面后,我假设我必须使用我的约束的Animator代理。但是,以下代码似乎无法完成工作。MonoMac上的NSLayoutConstraint动画
NSLayoutConstraint.constant ignoring animation http://cocoa-mono.org/archives/235/using-animator-with-frameorigin/
代码:
// makes sure we animate from 0 to calculated width
double newWidth = ...
widthConstraint.Constant = 0;
var animation = new NSAnimation() { Duration = 0.5, AnimationCurve = NSAnimationCurve.EaseInOut };
widthConstraint.Animations = new NSDictionary("constant", animation);
((NSLayoutConstraint)widthConstraint.Animator).Constant = newWidth;
这样做的结果是在控制具有newWidth
的宽度,但它不显示动画 - 它立即改变。