Instance Method
toggleSubview(_:dividerIndex:lastWidth:animationDuration:collapsesRightward:widthConstraint:completionHandler:) toggleSubview:dividerIndex:lastWidth:animationDuration:collapsesRightward:widthConstraint:completionHandler: toggleSubview_dividerIndex_lastWidth_animationDuration_collapsesRightward_widthConstraint_completionHandler_
Helper method to toggle a (vertically split) split view’s subview.
Declaration
func toggleSubview(_ subview: NSView, dividerIndex: UInt, lastWidth: UnsafeMutablePointer<CGFloat>, animationDuration: TimeInterval, collapsesRightward: Bool, widthConstraint: NSLayoutConstraint, completionHandler: ((Bool) -> Void)? = nil)func toggleSubview(_ subview: NSView, dividerIndex: UInt, lastWidth: UnsafeMutablePointer<CGFloat>, animationDuration: TimeInterval, collapsesRightward: Bool, widthConstraint: NSLayoutConstraint) async -> BoolDeclaration
- (void) toggleSubview:(NSView *) subview dividerIndex:(NSUInteger) dividerIndex lastWidth:(CGFloat *) lastWidth animationDuration:(NSTimeInterval) animationDuration collapsesRightward:(BOOL) collapsesRightward widthConstraint:(NSLayoutConstraint *) widthConstraint completionHandler:(void (^)(BOOL isOpen)) completionHandler;Declaration
toggleSubview_dividerIndex_lastWidth_animationDuration_collapsesRightward_widthConstraint_completionHandler_(subview: NSView, dividerIndex: int, lastWidth: float, animationDuration: float, collapsesRightward: bool, widthConstraint: NSLayoutConstraint, isOpen: bool, completionHandler)Parameters
subviewThe subview to toggle.
dividerIndexThe index of the divider to position.
lastWidthA reference to the variable you store the last width of the subview in.
animationDurationThe duration of the animation.
collapsesRightwardWhether you want to have the subview collapse rightward (or leftward, if NO).
widthConstraintThe width constraint you have applied to the subview so that it doesn’t become too narrow.
completionHandlerThe completion handler that is called, once the animation has ended.
Discussion
This is a helper method to toggle a split view’s subview. It is animated by calling -setPosition:ofDividerAtIndex:. There are two versions: one for split views with vertical dividers (this one) and another for those with horizontal dividers.