我试图弄清楚如何在垂直配置的 2 视图 NSSplitView 中动画切换(替换)子视图。我在我的 NSSplitView 子类中使用以下方法使其半工作:
要设置动画:
- (void)awakeFromNib {
// set delegate
[self setWantsLayer:YES];
CATransition *transition = [CATransition animation];
[transition setType:kCATransitionPush];
[transition setSubtype:kCATransitionFromBottom];
[transition setDuration:1.0];
[self setAnimations:[NSDictionary dictionaryWithObject:transition
forKey:@"subviews"]];
}
并执行它:
- (void)replaceRightView:(NSView *)newView animated:(BOOL)animate {
NSRect currentSize = [[[self subviews] objectAtIndex:1] frame];
[newView setFrame:currentSize];
if (animate) {
[[self animator] replaceSubview:[[self subviews] objectAtIndex:1]
with:newView];
} else {
[self replaceSubview:[[self subviews] objectAtIndex:1]
with:newView];
}
}
但是,这段代码的效果是把整个 NSSplitView 推开,而不仅仅是拆分右侧的子视图。
有没有办法只为子视图过渡设置动画?也许我使用了错误的动画键(“子视图”)?其他动画方法也可以。
谢谢!