Make the divider of an NSSplitView undraggable and don't show the dragging cursor

六眼飞鱼酱① 提交于 2019-12-31 09:44:27

问题


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:

- (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. :)


No, I don't want to use BWToolkit.


回答1:


Try using splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt: instead of 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.

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.




回答2:


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:.

Hope that helps someone else who lands here.



来源:https://stackoverflow.com/questions/4091560/make-the-divider-of-an-nssplitview-undraggable-and-dont-show-the-dragging-curso

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