我在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
的寬度,但它不顯示動畫 - 它立即改變。