NSScrollView how to start from top left corner

痴心易碎 提交于 2021-02-10 08:43:07

问题


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.


回答1:


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



回答2:


Swift 4 Method to invert axises :

from https://stackoverflow.com/a/40381180/5464805 thank's to Ben Leggiero :

import Cocoa

class FlippedView: NSView {
    override var isFlipped: Bool { return true }
}

Then in the storyboard, set this class to the NSView below the NSClipView and it do the trick. However it won't appear in StoryBoard so you'll have to build and run



来源:https://stackoverflow.com/questions/26871945/nsscrollview-how-to-start-from-top-left-corner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!