Skip to content

Instantly share code, notes, and snippets.

@umurgdk
Created November 21, 2021 16:47
Show Gist options
  • Save umurgdk/b8df7aad275a73130dbe2c9551e4da43 to your computer and use it in GitHub Desktop.
Save umurgdk/b8df7aad275a73130dbe2c9551e4da43 to your computer and use it in GitHub Desktop.
class FlippedClipView: NSClipView {
var stickyView: NSView?
var trailingConstraint: NSLayoutConstraint?
override var isFlipped: Bool { true }
override func layout() {
super.layout()
if trailingConstraint == nil, let scrollView = enclosingScrollView, let stickyView = stickyView {
trailingConstraint = stickyView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: 0)
trailingConstraint?.isActive = true
}
}
override var documentRect: NSRect {
let rect = super.documentRect
trailingConstraint?.constant = bounds.origin.x
return rect
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment