Instance Method
toggleSubview(_:dividerIndex:lastHeight:animationDuration:collapsesUpward:heightConstraint:completionHandler:) toggleSubview:dividerIndex:lastHeight:animationDuration:collapsesUpward:heightConstraint:completionHandler: toggleSubview_dividerIndex_lastHeight_animationDuration_collapsesUpward_heightConstraint_completionHandler_
Helper method to toggle a (horizontally split) split view’s subview.
Declaration
func toggleSubview(_ subview: NSView, dividerIndex: UInt, lastHeight: UnsafeMutablePointer<CGFloat>, animationDuration: TimeInterval, collapsesUpward: Bool, heightConstraint: NSLayoutConstraint, completionHandler: ((Bool) -> Void)? = nil)func toggleSubview(_ subview: NSView, dividerIndex: UInt, lastHeight: UnsafeMutablePointer<CGFloat>, animationDuration: TimeInterval, collapsesUpward: Bool, heightConstraint: NSLayoutConstraint) async -> BoolDeclaration
- (void) toggleSubview:(NSView *) subview dividerIndex:(NSUInteger) dividerIndex lastHeight:(CGFloat *) lastHeight animationDuration:(NSTimeInterval) animationDuration collapsesUpward:(BOOL) collapsesUpward heightConstraint:(NSLayoutConstraint *) heightConstraint completionHandler:(void (^)(BOOL isOpen)) completionHandler;Declaration
toggleSubview_dividerIndex_lastHeight_animationDuration_collapsesUpward_heightConstraint_completionHandler_(subview: NSView, dividerIndex: int, lastHeight: float, animationDuration: float, collapsesUpward: bool, heightConstraint: NSLayoutConstraint, isOpen: bool, completionHandler)Parameters
subviewThe subview to toggle.
dividerIndexThe index of the divider to position.
lastHeightA reference to the variable you store the last height of the subview in.
animationDurationThe duration of the animation.
collapsesUpwardWhether you want to have the subview collapse upward (or downward, if NO).
heightConstraintThe height 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 horizontal dividers (this one) and another for those with vertical dividers.