Shrink NSScroller of NSScrollView in layer-backed view

荒凉一梦 提交于 2019-12-24 15:07:28

问题


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

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.

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

It works, but:

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?


回答1:


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

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

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 to automatically set it as vertical
  2. width > height to automatically set it as horizontal

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.



来源:https://stackoverflow.com/questions/19233180/shrink-nsscroller-of-nsscrollview-in-layer-backed-view

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