मैं अपने अनुप्रयोगों में से एक के लिए एक ऑटोलायआउट-अनुकूल स्प्लिट व्यू क्लास बना रहा हूं। इसकी विभिन्न विशेषताओं में से यह है कि यह पैन को ध्वस्त कर सकता है, और उनके पतन को एनिमेट कर सकता है, जैसा कि आपने NSSplitView को देखा होगा।NSLayoutConstraint.constant एनीमेशन को अनदेखा कर रहा है
जब से मैं बाधाओं उपयोग कर रहा हूँ, मैं फलक पर एक आवश्यक चौड़ाई = (वर्तमान चौड़ाई) बाधा डाल रहा है, और फिर सेट करके ऐसा कर रहा हूँ प्राप्त करने बाधा के 0 के लिए निरंतर एक एनिमेटेड फैशन में:
- (NSLayoutConstraint*)newHiddenConstraintAnimated:(BOOL)animated {
NSLayoutConstraint * constraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:NSWidth(self.view.frame)];
constraint.priority = NSLayoutPriorityRequired;
CABasicAnimation * anim = [CABasicAnimation animation];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
anim.duration = 0.2;
constraint.animations = [NSDictionary dictionaryWithObject:anim forKey:@"constant"];
[self.view addConstraint:constraint];
[(animated ? constraint.animator : constraint) setConstant:0.0];
return constraint;
}
यह खूबसूरती से काम करता है। दुर्भाग्यवश, बाद में फलक का विस्तार करना इतना अच्छा किराया नहीं है।
- (void)removeHiddenConstraintAnimated:(BOOL)animated {
if(!animated) {
[self.view removeConstraint:self.hiddenConstraint];
}
else {
NSLayoutConstraint * constraint = self.hiddenConstraint;
NSView * theView = self.view;
[NSAnimationContext beginGrouping];
[constraint.animator setConstant:self.width];
[NSAnimationContext currentContext].completionHandler = ^{
[theView removeConstraint:constraint];
};
[NSAnimationContext endGrouping];
}
self.hiddenConstraint = nil;
}
अगर मैं कुछ समय कोड डालने, मैं देख सकता है कि पूरा होने हैंडलर लगभग तुरंत आग, बाधा को हटाने से पहले यह चेतन करने के लिए समय है। NSAnimationContext पर एक अवधि निर्धारित करने से कोई प्रभाव नहीं पड़ता है।
कोई विचार क्या मैं यहां गलत कर सकता हूं?
क्या आपने कभी इस स्प्लिट व्यू क्लास को समाप्त किया था? ओपन-सोर्स जा रहा है इसकी संभावना? –
मैं इस समय की योजना नहीं बना रहा हूं। यह इस एप्लिकेशन के लिए काफी विशिष्ट है, और मेरा मानना है कि [PURRDACTED] में 'NSSplitView' को ऑटोलायआउट के साथ बेहतर काम करने के लिए फिर से डिजाइन किया गया है। –
ओह, गॉचा। [Redacted] के संबंध में, ऑटो लेआउट के संबंध में यह अच्छी सुविधा है, लेकिन निश्चित रूप से यह पुराने लक्ष्य के साथ पिछड़ा नहीं है। ओह ठीक है, मैं अपना खुद का अनुमान लगाऊंगा! :) –