调整NSSplitView的大小

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调整NSSplitView的大小相关的知识,希望对你有一定的参考价值。

This provides a nice split view resizing method with a minimum size restraint. You HAVE to specify MIN_LEFT_PANE_W for this to work.
  1. - (void) splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize {
  2. // http://www.wodeveloper.com/omniLists/macosx-dev/2003/May/msg00261.html
  3.  
  4. // grab the splitviews
  5. NSView *left = [[sender subviews] objectAtIndex:0];
  6. NSView *right = [[sender subviews] objectAtIndex:1];
  7.  
  8. float dividerThickness = [sender dividerThickness];
  9.  
  10. // get the different frames
  11. NSRect newFrame = [sender frame];
  12. NSRect leftFrame = [left frame];
  13. NSRect rightFrame = [right frame];
  14.  
  15. // change in width for this redraw
  16. int dWidth = newFrame.size.width - oldSize.width;
  17.  
  18. // ratio of the left frame width to the right used for resize speed when both panes are being resized
  19. float rLeftRight = (leftFrame.size.width - MIN_LEFT_PANEL_W) / rightFrame.size.width;
  20.  
  21. // resize the height of the left
  22. leftFrame.size.height = newFrame.size.height;
  23. leftFrame.origin = NSMakePoint(0,0);
  24.  
  25. // resize the left & right pane equally if we are shrinking the frame
  26. // resize the right pane only if we are increasing the frame
  27. // when resizing lock at minimum width for the left panel
  28. if(leftFrame.size.width <= MIN_LEFT_PANEL_W && dWidth < 0) {
  29. rightFrame.size.width += dWidth;
  30. } else if(dWidth > 0) {
  31. rightFrame.size.width += dWidth;
  32. } else {
  33. leftFrame.size.width += dWidth * rLeftRight;
  34. rightFrame.size.width += dWidth * (1 - rLeftRight);
  35. }
  36.  
  37. rightFrame.size.width = newFrame.size.width - leftFrame.size.width - dividerThickness;
  38. rightFrame.size.height = newFrame.size.height;
  39. rightFrame.origin.x = leftFrame.size.width + dividerThickness;
  40.  
  41. [left setFrame:leftFrame];
  42. [right setFrame:rightFrame];
  43. }

以上是关于调整NSSplitView的大小的主要内容,如果未能解决你的问题,请参考以下文章

NSSplitView 中的 NSOpenGLView

NSTableView 在 NSSplitView 中显示不正确

android - 调整片段大小

调整片段中 TextView 的文本大小

在 Kotlin 中调整对话框片段的大小

键盘打开时,带有片段的活动不会调整大小