在层支持视图中缩小NSScrollView的NSScroller [英] Shrink NSScroller of NSScrollView in layer-backed view

查看:420
本文介绍了在层支持视图中缩小NSScrollView的NSScroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题(Bug?):说我有一个 WebView ,它将垂直滚动。

I'm experiencing a weird problem (Bug?): Say I have a WebView, which will scroll vertically.

我现在想要缩小 mainFrame 的垂直滚动条,使其高度小于 NSScrollView 本身。

I now want to shrink the mainFrame's vertical scroller a little bit, so that its height is smaller than the NSScrollView itself.

这样做的原因是我想将两个视图(顶部和底部边缘)固定在网络视图上方。

The reason for this is that I want to pin two views (on top and on bottom edge) above the webview.

通过改变verticalScroller的框架(改变原点和高度),我在frameLoad委托方法中很容易做到了。

I did that easily in the frameLoad delegate method by altering the verticalScroller's frame (altering origin and height).

它可以工作,但

It works, but:

但是一旦我设置了webView,父NSView要层支持,它停止工作,滚动重置自己的默认位置和高度。

However once I set the webView and it's parent NSView to be layer-backed, it stops working, the scroller resets itself to the default position and height.

现在我不知道这是否是一个错误。

Now I don't know if this is a bug or not. Is there any other way I could try to 'inset' the scroller?

推荐答案

是否有其他方法可以尝试'插入'滚动器?将它设置为NSScrollView的垂直滚动并覆盖

Have you tried subclassing NSScroller, setting it as the vertical scroller for your NSScrollView and overriding

-(void) setFrameOrigin:(NSPoint)origin;
-(void) setFrameSize:(NSSize)size;

我假设使NSView层支持的原因frameSize被重新设置(NSScrollView似乎需要相当多因为当你创建一个自定义滚动器,没有干净的方式设置NSScroller水平或垂直,除了调用 - initWithFrame

I assume making the NSView layer-backed causes frameSize to be set again(NSScrollView seems to take quite a bit of control on this because when you create a custom scroller, there is no "clean" way to set an NSScroller as horizontal or vertical other than calling -initWithFrame: with


  1. height> width自动设置为垂直

  2. strong> horizo​​ntal>

  1. height > width to automatically set it as vertical
  2. width > height to automatically set it as horizontal

我的其他建议是,如果你想NSScroller不能完全反映其父NSScrollView你最好有一个NSView作为webview的内容视图和NSView有3个子视图顶部和底部的两个视图 pinned 和一个NSScrollView在中间没有自定义NSScroller在这种情况下是必要的。

My other suggestion would be, if you want the NSScroller to not fully reflect the size of its parent NSScrollView would you be better off having an NSView as the content view of the webview. And the NSView have 3 subviews. Two views at the top and bottom pinned, and one NSScrollView in the middle. No custom NSScroller necessary in this case.

这篇关于在层支持视图中缩小NSScrollView的NSScroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆