使NSSplitView的分隔符不可拖动,并且不显示拖动光标

时间:2021-10-11 22:55:32

I have an NSSplitView (NO UISplitView(Controller)!!) with three subviews. Now, for the last divider (index 1), I want the divider to not show the dragging cursor (two arrows pointing out of eachother). I have this to stop the dragging, but the cursor is still showing up:

我有一个NSSplitView(没有UISplitView(控制器)!!)有三个子视图。现在,对于最后一个分隔符(索引1),我希望这个分隔符不显示拖动光标(两个箭头指向彼此)。我有这个来停止拖动,但是光标仍然显示:

- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex {
  if (dividerIndex == 1) {
    return [splitView frame].size.width - 161;
  }
}

Note that I only want to hide the cursor for the divider at index 1. Can anyone help me? Thanks. :)

注意,我只想隐藏索引1处的分隔符的游标。谁能帮我吗?谢谢。:)


No, I don't want to use BWToolkit.

不,我不想使用BWToolkit。

2 个解决方案

#1


0  

Try using splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt: instead of splitView:constrainSplitPosition:ofSubviewAt:.

尝试使用splitView:constrainMaxCoordinate:ofSubviewAt:和splitView:constrainMinCoordinate:ofSubviewAt:而不是splitView:constrainSplitPosition:ofSubviewAt:。

The former two methods are called once as the user drags the mouse and they give enough information for NSSplitView to know how to change the cursor during the drag.

当用户拖拽鼠标时,会调用前两个方法,它们会为NSSplitView提供足够的信息,让它知道如何在拖拽过程中更改光标。

The latter is called repeatedly as the user drags the splitter, so NSSplitView doesn't have enough information to know that you're returning a constant value each time and therefore can't change the cursor.

当用户拖拽splitter时,会反复调用后者,因此NSSplitView没有足够的信息来知道每次都返回一个常量值,因此无法更改游标。

#2


73  

I know this has been answered for a while, but the supplied answer did not suit my needs.

我知道这个问题已经回答了一段时间,但提供的答案并不适合我的需要。

The delegate method splitView:effectiveRect:forDrawnRect:ofDividerAtIndex: allows you to set the effective rectangle for dragging the divider. If you return NSZeroRect no drag cursor will ever appear, regardless of your setup in splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt:.

委托方法splitView:effective verect:forDrawnRect:ofDividerAtIndex:允许您设置拖动分割器的有效矩形。如果你返回NSZeroRect,就不会出现任何拖动光标,不管你在splitView中的设置是什么:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt:。

Hope that helps someone else who lands here.

希望这能帮助到来到这里的其他人。

#1


0  

Try using splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt: instead of splitView:constrainSplitPosition:ofSubviewAt:.

尝试使用splitView:constrainMaxCoordinate:ofSubviewAt:和splitView:constrainMinCoordinate:ofSubviewAt:而不是splitView:constrainSplitPosition:ofSubviewAt:。

The former two methods are called once as the user drags the mouse and they give enough information for NSSplitView to know how to change the cursor during the drag.

当用户拖拽鼠标时,会调用前两个方法,它们会为NSSplitView提供足够的信息,让它知道如何在拖拽过程中更改光标。

The latter is called repeatedly as the user drags the splitter, so NSSplitView doesn't have enough information to know that you're returning a constant value each time and therefore can't change the cursor.

当用户拖拽splitter时,会反复调用后者,因此NSSplitView没有足够的信息来知道每次都返回一个常量值,因此无法更改游标。

#2


73  

I know this has been answered for a while, but the supplied answer did not suit my needs.

我知道这个问题已经回答了一段时间,但提供的答案并不适合我的需要。

The delegate method splitView:effectiveRect:forDrawnRect:ofDividerAtIndex: allows you to set the effective rectangle for dragging the divider. If you return NSZeroRect no drag cursor will ever appear, regardless of your setup in splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt:.

委托方法splitView:effective verect:forDrawnRect:ofDividerAtIndex:允许您设置拖动分割器的有效矩形。如果你返回NSZeroRect,就不会出现任何拖动光标,不管你在splitView中的设置是什么:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt:。

Hope that helps someone else who lands here.

希望这能帮助到来到这里的其他人。