Skip to content

Instantly share code, notes, and snippets.

@swillits
Created December 14, 2017 18:59
Show Gist options
  • Save swillits/88285e2555a5201d1da92924fb3f8153 to your computer and use it in GitHub Desktop.
Save swillits/88285e2555a5201d1da92924fb3f8153 to your computer and use it in GitHub Desktop.
Flip an NSScrollView Properly
/// Pins the document to the top-left of the clip view
final class FlippingClipView: NSClipView {
override func constrainBoundsRect(_ proposedBounds: NSRect) -> NSRect {
var constrained = super.constrainBoundsRect(proposedBounds)
guard let documentHeight = documentView?.frame.height else {
return constrained
}
if documentHeight < proposedBounds.height {
constrained.origin.y -= constrained.height - documentHeight
constrained.size.height = documentHeight
}
return constrained
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment