Created
December 14, 2017 18:59
-
-
Save swillits/88285e2555a5201d1da92924fb3f8153 to your computer and use it in GitHub Desktop.
Flip an NSScrollView Properly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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