如何隐藏 nssplitview 的分隔线?
现在,我想在应用程序运行时根据我的情况隐藏或显示分隔线。使用了这个委托方法:
- (BOOL)splitView:(NSSplitView *)splitView shouldHideDividerAtIndex:(NSInteger)dividerIndex
{
if (A)
return YES;
else
return NO;
}
但它不起作用,为什么?如何使用这个方法呢?非常感谢!
Now I want to hide or show with my condition a divider when my app run. used this delegate method:
- (BOOL)splitView:(NSSplitView *)splitView shouldHideDividerAtIndex:(NSInteger)dividerIndex
{
if (A)
return YES;
else
return NO;
}
but it didn't work , why? How to used this method? Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据@carmin的注释,上面,覆盖 NSSplitView
dividerThickness
属性是唯一对我有用的东西(具体来说,从 splitView: effectiveRect:forDrawnRect:ofDividerAtIndex: NSSplitView 委托方法返回 NSRectZero — 如此处详细说明 - 不起作用并导致浮动分隔线与视图本身脱节)。这是 Swift 中的代码:
Further to @carmin’s note, above, overriding the NSSplitView
dividerThickness
property is the only thing that worked for me (specifically, returning NSRectZero from the splitView:effectiveRect:forDrawnRect:ofDividerAtIndex: NSSplitView delegate method — as detailed here – didn’t work and resulted in floating dividers disjointed from the views themselves).Here’s the code in Swift:
分割视图将该消息发送给其委托,以询问委托是否应该隐藏该分隔线。所以, 成为代理人,并回答分割视图的问题。
请务必查看 文档。该消息可能无法实现您想要的效果。该文档列出了您可以通过响应该消息执行的所有操作。
The split view sends that message to its delegate, to ask the delegate whether it should hide that divider. So, be the delegate, and answer the split view's question.
Be sure to check out the documentation. It's possible that that message won't accomplish what you want it to. The documentation lists everything you can do by responding to that message.
您可以重载 NSSplitView-dividerThickness 并返回 0 以隐藏所有分隔线。您可以重载 NSSplitView-drawDividerInRect: 对分隔线进行单独控制(选择是否允许 super 绘制分隔线)。即使子视图可见,这些选择也有效。
You can overload NSSplitView-dividerThickness and return 0 to hide all of the dividers. You can overload NSSplitView-drawDividerInRect: to have individual control over the dividers (choosing to allow super to draw the divider or not). These choices work even when the subviews are visible.
以下是如何在 Obj-C 中执行此操作,不涉及子类化。确保您已连接 IB 中的 SplitView 委托。
然后在您的委托类中:
这将在分割视图关闭时隐藏分隔线,但在打开时显示分隔线。
如果您不希望他们即使在打开时也能够拖动它,只需删除第一个方法中的所有代码并仅返回 NSZeroRect 即可。在第二种方法中做同样的事情,只返回 YES。
Here's how to do it in Obj-C that doesn't involve subclassing. Make sure that you've got the SplitView delegate in IB connected.
Then in your delegate class:
This will hide the divider when the split view is closed, but show it when it is open.
If you don't want them to be able to drag it even when its open, just cut out all the code in the first method and return only NSZeroRect. Do the same in the second method and only return YES.
为了子孙后代,使用 Swift 时,您可以调用委托函数
splitView(_: effectiveRect:forDrawnRect:ofDividerAtIndex:)
并让它返回一个空的 NSRectFor the sake of posterity, working with Swift you can call the delegate function
splitView(_:effectiveRect:forDrawnRect:ofDividerAtIndex:)
and just have it return an empty NSRect在 NSSplitView 的自定义类中使用此类:
对我来说它有效!
Use this class in Custom class of NSSplitView:
For me it worked!