Search code examples
objective-ccocoaosx-yosemiteappkitnsscrollview

NSScrollView how to start from top left corner


How to set scrollView document view to be pinned to top left corner? If scrollView is big enough/bigger than its content, everything is drawn from bottom to up and it not looks right. I have to override isFlipped of scrollView?

I was searching internet and overriding isFlipped to return trueis not everything. I don't want to make my documentView flipped because then I have to make changes in that class to make everything looks like I want.


Solution

  • I created simple NSView class as an container for elements that i want to have inside my scrollView and everything looks perfect. I hope this will help someone!

    @interface FlippedView : NSView
    
    @end
    

    and implementation:

    @implementation FlippedView
    
    - (void)drawRect:(NSRect)dirtyRect {
        [super drawRect:dirtyRect];
    
        // Drawing code here.
    }
    
    - (BOOL) isFlipped
    {
        return YES;
    }
    
    @end