我在XIB中使用自动布局设置了如下所示的接口。
[Left Pane]-[Center Pane]-[Right Pane]
[ Bottom Pane ]
目前,它支持每个窗格的最大和最小宽度/高度以及通过双击分隔符或使用NSSegmentedControl折叠子视图。现在我想要做的是动画折叠当用户切换NSSegmentedControl时发生的情况。我已经看到很多关于使用NSSplitView设置动画来折叠子视图的示例,但没有一个使用自动布局来实现它。
我尝试遵循WWDC 2012年有关自动布局演示的约束动画演示,但由于这是我第一次启用自动布局,我还没有弄清楚如何做到这一点。
以下是我目前拥有的内容。
NSArray *constraints = [self.leftPane constraints];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d", NSLayoutAttributeWidth];
NSArray *filteredArray = [constraints filteredArrayUsingPredicate:predicate];
[self.leftPane removeConstraints:filteredArray];
[self.lcrSplitView layoutSubtreeIfNeeded];
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
[context setAllowsImplicitAnimation:YES];
NSLayoutConstraint *newWidth = [NSLayoutConstraint constraintWithItem:self.leftPane
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:0.0f
constant:0.0f];
[self.leftPane addConstraint:newWidth];
[self.lcrSplitView layoutSubtreeIfNeeded];
} completionHandler:^{}];