NSScrollView with browsing content without access?

Is there a way I can set my scrollview so as not to crop its contents? (Which is NSTextView)

I have a subclass of NSScrollView and want its contents not to be bound to its borders. I tried to override:

- (BOOL) wantsDefaultClipping{
    return NO;
}

in MyScrollViewand in MytextViewwithout any effect. In iOS, I would just do: myuitextView.clipsToBounds=NO;how to do it in Cocoa?

EDIT

This is an example of what I want to achieve, but in the poppy Scrollview is white, the scroller never goes beyond its borders, but the text does as I did myuitextView.clipsToBounds=NO

See image here

EDIT2

I would not mind a clip of my mind, as @Josh suggested. But the real behavior that I would like to have can be explained with the help of this picture:

normal NSScrollView with NSTextView

***** EDIT *****, ? , , , , , , , .

: NSImageView, , ? A: 1.Scroller . NSImageView, , / NSImageView, .

, NSClipView. , . ? , NSTextView, / ? ?

.

+2
4

, 2016, , , - . , , , .

, , , .

( NSTextView ) , :

    // For transparent title.
    window.titlebarAppearsTransparent = true
    window.styleMask = window.styleMask | NSFullSizeContentViewWindowMask
    window.appearance = NSAppearance(named: NSAppearanceNameVibrantLight)

NSWindow contentView.

- , :

// Make a constraint for SOMEVIEW to the top layout guide of the window:
let topEdgeConstraint = NSLayoutConstraint(
item: SOMEVIEW, attribute: NSLayoutAttribute.Top,
relatedBy: NSLayoutRelation.Equal,
toItem: window.contentLayoutGuide,
attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 0.0)

// Turn the constraint on automatically:    
topEdgeConstraint.active = true

( + , ). WWDC 2015 : https://developer.apple.com/videos/play/wwdc2014/220/

, , IB , . , :

scrollView.automaticallyAdjustsContentInsets = true

, /. ( ), scrollview /, .

, , . , , , . NSWindow, self .

// MARK: NSTextViewDelegate
func textViewDidChangeSelection(notification: NSNotification) {
    scrollIfCaretIsObscured()
    textView.needsDisplay = true // Prevents a selection rendering glitch from sticking around
}

// MARK: My Scrolling Functions

func scrollIfCaretIsObscured() {
    let rect = caretRectInWindow()
    let y: CGFloat = caretYPositionInWindow() - rect.height
    // Todo: Make this consider the text view ruler height, if present:
    let tbHeight: CGFloat
    if textView.rulerVisible {
        // Ruler is shown:
        tbHeight = (try! titlebarHeight()) + textViewRulerHeight
    } else {
        // Ruler is hidden
        tbHeight = try! titlebarHeight()
    }
    if y <= tbHeight {
        scrollToCursor()
    }
}

func caretYPositionInWindow() -> CGFloat {
    let caretRectInWin: NSRect = caretRectInWindow()
    let caretYPosInWin: CGFloat = self.contentView!.frame.height - caretRectInWin.origin.y
    return caretYPosInWin
}

func caretRectInWindow() -> CGRect {
    // My own version of something based off of an old, outdated
    // answer on stack overflow.
    // Credit: http://stackoverflow.com/questions/6948914/nspopover-below-caret-in-nstextview
    let caretRect: NSRect = textView.firstRectForCharacterRange(textView.selectedRange(), actualRange: nil)
    let caretRectInWin: NSRect = self.convertRectFromScreen(caretRect)
    return caretRectInWin
}

/// Scrolls to the current caret position inside the text view.
/// - Parameter textView: The specified text view to work with.
func scrollToCursor() {
    let caretRectInScreenCoords = textView.firstRectForCharacterRange(textView.selectedRange(), actualRange: nil)
    let caretRectInWindowCoords = self.convertRectFromScreen(caretRectInScreenCoords)
    let caretRectInTextView = textView.convertRect(caretRectInWindowCoords, fromView: nil)
    textView.scrollRectToVisible(caretRectInTextView)
}

enum WindowErrors: ErrorType {
    case CannotFindTitlebarHeight
}

/// Calculates the combined height of the titlebar and toolbar.
/// Don't try this at home.
func titlebarHeight() throws -> CGFloat {
    // Try the official way first:
    if self.titlebarAccessoryViewControllers.count > 0 {
        let textViewInspectorBar = self.titlebarAccessoryViewControllers[0].view
        if let titlebarAccessoryClipView = textViewInspectorBar.superview {
            if let view = titlebarAccessoryClipView.superview {
                if let titleBarView = view.superview {
                    let titleBarHeight: CGFloat = titleBarView.frame.height
                    return titleBarHeight
                }
            }
        }
    }
    throw WindowErrors.CannotFindTitlebarHeight
}

, !

+1

frame frame .

0

, , . iOS, Mac, .

drawRect: -[NSBezierPath setClip:]:

- (void)drawRect:(NSRect)dirtyRect {

    [NSGraphicsContext saveGraphicsState];
    [[NSBezierPath bezierPathWithRect:[[self documentView] frame]] setClip];

    //...

    [NSGraphicsContext restoreGraphicsState];
}

, , , NSClipView, , , . , NSScrollView.

0

. AFAIK, NSViews . , , , , UIView . , , , , - (- NSScrollView, , , ), , , . , NSClipView viewBoundsChanged: / viewFrameChanged: , , , "".

0

All Articles