xcode 如何设置 NSScroll 视图的默认位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5834056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How I set the default position of a NSScroll view?
提问by Javier Beltrán
I have a trouble with a NSScrollview in my aplication because it always start at the bottom of the window. How could make it start in the top?
我的应用程序中的 NSScrollview 有问题,因为它总是从窗口底部开始。如何让它从顶部开始?
回答by Anne
Try something like this:
尝试这样的事情:
NSPoint pointToScrollTo = NSMakePoint ( , ); // Any point you like.
[[scrollView contentView] scrollToPoint: pointToScrollTo];
[scrollView reflectScrolledClipView: [scrollView contentView]];
回答by jscs
A solution is given in the Scroll View Programming Guide, Scrolling to a Specific Location. You can use -[NSView scrollPoint:]
to set the clip view's origin.
Scroll View Programming Guide, Scrolling to a Specific Location 中给出了一个解决方案。您可以使用-[NSView scrollPoint:]
来设置剪辑视图的原点。
// A controller which has an outlet to the scroll view
- (void)awakeFromNib {
// Not checking for flipped document view. See sample code.
// New origin should be
// (documentView.frame.y + documentView.frame.height) - clipView.bounds.height
NSPoint newOrigin = NSMakePoint(0, NSMaxY([[scrollView documentView] frame]) -
[[scrollView contentView] bounds].size.height);
[[scrollView documentView] scrollPoint:newOrigin];
}
回答by Selcaby
If you have a custom NSView subclass inside the NSScrollView, try overriding isFlipped
:
如果您在 NSScrollView 中有自定义 NSView 子类,请尝试覆盖isFlipped
:
- (BOOL)isFlipped
{
return YES;
}
This puts the view's origin at the top, which should make the NSScrollView do what you want.
这将视图的原点放在顶部,这应该使 NSScrollView 做你想做的事。
However, it will also flip the coordinates of everything inside your view.
但是,它也会翻转视图中所有内容的坐标。