splitView 上的奇怪行为:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize in os x Lion

发布于 2024-12-01 08:45:39 字数 6806 浏览 1 评论 0原文

我正在构建一个具有两个分割视图的应用程序(右侧分割视图中有一个分割视图) 但升级到 OS X Lion 后我遇到了问题。

当您使用右下角的调整大小操作(即同时更改高度和宽度)时,应用程序会崩溃。

当我注释掉这段代码时,奇怪的行为消失了,但是分割视图会崩溃,这是我不想要的。

(-(BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview) 不返回

-(void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize {
NSRect newFrame = [splitView frame];                           // get the new size of the whole splitView

if (newFrame.size.width == oldSize.width) {                 // if the width hasn't changed
    [splitView adjustSubviews];                                 // tell sender to adjust subviews
    return;
}

// grab the splitviews
NSView *left = [[splitView subviews] objectAtIndex:0];
NSView *right = [[splitView subviews] objectAtIndex:1];

float dividerThickness = [splitView dividerThickness];

// get the different frames
NSRect leftFrame = [left frame];
NSRect rightFrame = [right frame];

// change in width for this redraw
int dWidth  = newFrame.size.width - oldSize.width;

if ([splitView.identifier isEqualToString:@"MainSplitView"])
{
    // ratio of the left frame width to the right used for resize speed when both panes are being resized
    float rLeftRight = (leftFrame.size.width - MainMIN_LEFT_PANEL_W) / rightFrame.size.width;

    // resize the height of the left
    leftFrame.size.height = newFrame.size.height;
    leftFrame.origin = NSMakePoint(0,0);

    // resize the left & right pane equally if we are shrinking the frame
    // resize the right pane only if we are increasing the frame
    // when resizing lock at minimum width for the left panel
    if(leftFrame.size.width <= MainMIN_LEFT_PANEL_W && dWidth < 0) {
        rightFrame.size.width += dWidth;
    } else if(dWidth > 0) {
        rightFrame.size.width += dWidth;
    } else {
        leftFrame.size.width += dWidth * rLeftRight;
        rightFrame.size.width += dWidth * (1 - rLeftRight);
    }

    rightFrame.size.width = newFrame.size.width - leftFrame.size.width - dividerThickness;
    rightFrame.size.height = newFrame.size.height;
    rightFrame.origin.x = leftFrame.size.width + dividerThickness;
}
else if ([splitView.identifier isEqualToString:@"SecondSplitView"])
{
    //NSView *MainRight = [[SplitView subviews] objectAtIndex:1];
    //float MinWidth = MainRight.frame.size.width - SubMIN_RIGHT_PANEL_W;
    // ratio of the left frame width to the right used for resize speed when both panes are being resized
    float rLeftRight = (rightFrame.size.width - SubMIN_RIGHT_PANEL_W) / leftFrame.size.width;

    // resize the height of the left
    leftFrame.size.height = newFrame.size.height;
    leftFrame.origin = NSMakePoint(0,0);

    // resize the left & right pane equally if we are shrinking the frame
    // resize the right pane only if we are increasing the frame
    // when resizing lock at minimum width for the left panel
    if(rightFrame.size.width <= SubMIN_RIGHT_PANEL_W && dWidth < 0) {
        leftFrame.size.width += dWidth;
    } else if(dWidth > 0) {
        leftFrame.size.width += dWidth;
    } else {
        rightFrame.size.width += dWidth * rLeftRight;
        leftFrame.size.width += dWidth * (1 - rLeftRight);
    }

    leftFrame.size.width = newFrame.size.width - rightFrame.size.width - dividerThickness;
    leftFrame.size.height = newFrame.size.height;
    rightFrame.origin.x = leftFrame.size.width + dividerThickness;
}

[left setFrame:leftFrame];
[right setFrame:rightFrame]; }

崩溃日志:

    2011-08-24 18:36:15.670 MyApplication[29947:407] -[NSTextFieldCell length]: unrecognized selector sent to instance 0x10231a1c0
2011-08-24 18:36:15.672 MyApplication[29947:407] -[NSTextFieldCell length]: unrecognized selector sent to instance 0x10231a1c0
2011-08-24 18:36:15.675 MyApplication[29947:407] (
    0   CoreFoundation                      0x00007fff8cd31986 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff8be11d5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8cdbd5ae -[NSObject doesNotRecognizeSelector:] + 190
    3   CoreFoundation                      0x00007fff8cd1e803 ___forwarding___ + 371
    4   CoreFoundation                      0x00007fff8cd1e618 _CF_forwarding_prep_0 + 232
    5   CoreFoundation                      0x00007fff8cc95176 CFStringGetLength + 118
    6   CoreFoundation                      0x00007fff8cc99d91 CFStringAppend + 241
    7   CoreFoundation                      0x00007fff8cc94c18 __CFStringAppendFormatCore + 11448
    8   CoreFoundation                      0x00007fff8cce73eb _CFStringCreateWithFormatAndArgumentsAux + 107
    9   CoreFoundation                      0x00007fff8cd5f7c2 _CFLogvEx + 114
    10  Foundation                          0x00007fff95aa153f NSLogv + 89
    11  Foundation                          0x00007fff95aa14dd NSLog + 130
    12  AppKit                              0x00007fff91cf1bc6 -[NSSplitView _validateSubviewFrames] + 2004
    13  AppKit                              0x00007fff91cb4e31 -[NSSplitView resizeSubviewsWithOldSize:] + 739
    14  AppKit                              0x00007fff91b9d5e5 -[NSView setFrameSize:] + 955
    15  AppKit                              0x00007fff91b9ce9a -[NSView setFrame:] + 268
    16  AppKit                              0x00007fff91c791a0 -[NSView resizeWithOldSuperviewSize:] + 1040
    17  AppKit                              0x00007fff91c78d15 -[NSView resizeSubviewsWithOldSize:] + 200
    18  AppKit                              0x00007fff91b9d5e5 -[NSView setFrameSize:] + 955
    19  AppKit                              0x00007fff91cb0899 -[NSWindow _oldPlaceWindow:] + 1551
    20  AppKit                              0x00007fff91c5b7bb -[NSWindow _setFrameCommon:display:stashSize:] + 1948
    21  AppKit                              0x00007fff91c5b019 -[NSWindow setFrame:display:] + 60
    22  AppKit                              0x00007fff91cab9db -[NSWindow(NSWindowResizing) _resizeWithEvent:] + 1223
    23  AppKit                              0x00007fff91cab4af -[NSTitledFrame mouseDown:] + 187
    24  AppKit                              0x00007fff91cab3c1 -[NSThemeFrame mouseDown:] + 626
    25  AppKit                              0x00007fff91c2b66e -[NSWindow sendEvent:] + 6280
    26  AppKit                              0x00007fff91bc3f19 -[NSApplication sendEvent:] + 5665
    27  AppKit                              0x00007fff91b5a42b -[NSApplication run] + 548
    28  AppKit                              0x00007fff91dd852a NSApplicationMain + 867
    29  MyApplication                         0x0000000100001e42 main + 34
    30  MyApplication                         0x0000000100001e14 start + 52
)

I'm building an application with two split views (one split view in side right split view)
But i'm having problems after upgrading to OS X Lion.

The application crashes when you use the lower right resize action, ie change the height and width at the same time.

When i comment out this code the strange behavior goes away, but then the split view will collapse, which is something I don't want.

(-(BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview) is returning no

-(void)splitView:(NSSplitView *)splitView resizeSubviewsWithOldSize:(NSSize)oldSize {
NSRect newFrame = [splitView frame];                           // get the new size of the whole splitView

if (newFrame.size.width == oldSize.width) {                 // if the width hasn't changed
    [splitView adjustSubviews];                                 // tell sender to adjust subviews
    return;
}

// grab the splitviews
NSView *left = [[splitView subviews] objectAtIndex:0];
NSView *right = [[splitView subviews] objectAtIndex:1];

float dividerThickness = [splitView dividerThickness];

// get the different frames
NSRect leftFrame = [left frame];
NSRect rightFrame = [right frame];

// change in width for this redraw
int dWidth  = newFrame.size.width - oldSize.width;

if ([splitView.identifier isEqualToString:@"MainSplitView"])
{
    // ratio of the left frame width to the right used for resize speed when both panes are being resized
    float rLeftRight = (leftFrame.size.width - MainMIN_LEFT_PANEL_W) / rightFrame.size.width;

    // resize the height of the left
    leftFrame.size.height = newFrame.size.height;
    leftFrame.origin = NSMakePoint(0,0);

    // resize the left & right pane equally if we are shrinking the frame
    // resize the right pane only if we are increasing the frame
    // when resizing lock at minimum width for the left panel
    if(leftFrame.size.width <= MainMIN_LEFT_PANEL_W && dWidth < 0) {
        rightFrame.size.width += dWidth;
    } else if(dWidth > 0) {
        rightFrame.size.width += dWidth;
    } else {
        leftFrame.size.width += dWidth * rLeftRight;
        rightFrame.size.width += dWidth * (1 - rLeftRight);
    }

    rightFrame.size.width = newFrame.size.width - leftFrame.size.width - dividerThickness;
    rightFrame.size.height = newFrame.size.height;
    rightFrame.origin.x = leftFrame.size.width + dividerThickness;
}
else if ([splitView.identifier isEqualToString:@"SecondSplitView"])
{
    //NSView *MainRight = [[SplitView subviews] objectAtIndex:1];
    //float MinWidth = MainRight.frame.size.width - SubMIN_RIGHT_PANEL_W;
    // ratio of the left frame width to the right used for resize speed when both panes are being resized
    float rLeftRight = (rightFrame.size.width - SubMIN_RIGHT_PANEL_W) / leftFrame.size.width;

    // resize the height of the left
    leftFrame.size.height = newFrame.size.height;
    leftFrame.origin = NSMakePoint(0,0);

    // resize the left & right pane equally if we are shrinking the frame
    // resize the right pane only if we are increasing the frame
    // when resizing lock at minimum width for the left panel
    if(rightFrame.size.width <= SubMIN_RIGHT_PANEL_W && dWidth < 0) {
        leftFrame.size.width += dWidth;
    } else if(dWidth > 0) {
        leftFrame.size.width += dWidth;
    } else {
        rightFrame.size.width += dWidth * rLeftRight;
        leftFrame.size.width += dWidth * (1 - rLeftRight);
    }

    leftFrame.size.width = newFrame.size.width - rightFrame.size.width - dividerThickness;
    leftFrame.size.height = newFrame.size.height;
    rightFrame.origin.x = leftFrame.size.width + dividerThickness;
}

[left setFrame:leftFrame];
[right setFrame:rightFrame]; }

Crashlog:

    2011-08-24 18:36:15.670 MyApplication[29947:407] -[NSTextFieldCell length]: unrecognized selector sent to instance 0x10231a1c0
2011-08-24 18:36:15.672 MyApplication[29947:407] -[NSTextFieldCell length]: unrecognized selector sent to instance 0x10231a1c0
2011-08-24 18:36:15.675 MyApplication[29947:407] (
    0   CoreFoundation                      0x00007fff8cd31986 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff8be11d5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8cdbd5ae -[NSObject doesNotRecognizeSelector:] + 190
    3   CoreFoundation                      0x00007fff8cd1e803 ___forwarding___ + 371
    4   CoreFoundation                      0x00007fff8cd1e618 _CF_forwarding_prep_0 + 232
    5   CoreFoundation                      0x00007fff8cc95176 CFStringGetLength + 118
    6   CoreFoundation                      0x00007fff8cc99d91 CFStringAppend + 241
    7   CoreFoundation                      0x00007fff8cc94c18 __CFStringAppendFormatCore + 11448
    8   CoreFoundation                      0x00007fff8cce73eb _CFStringCreateWithFormatAndArgumentsAux + 107
    9   CoreFoundation                      0x00007fff8cd5f7c2 _CFLogvEx + 114
    10  Foundation                          0x00007fff95aa153f NSLogv + 89
    11  Foundation                          0x00007fff95aa14dd NSLog + 130
    12  AppKit                              0x00007fff91cf1bc6 -[NSSplitView _validateSubviewFrames] + 2004
    13  AppKit                              0x00007fff91cb4e31 -[NSSplitView resizeSubviewsWithOldSize:] + 739
    14  AppKit                              0x00007fff91b9d5e5 -[NSView setFrameSize:] + 955
    15  AppKit                              0x00007fff91b9ce9a -[NSView setFrame:] + 268
    16  AppKit                              0x00007fff91c791a0 -[NSView resizeWithOldSuperviewSize:] + 1040
    17  AppKit                              0x00007fff91c78d15 -[NSView resizeSubviewsWithOldSize:] + 200
    18  AppKit                              0x00007fff91b9d5e5 -[NSView setFrameSize:] + 955
    19  AppKit                              0x00007fff91cb0899 -[NSWindow _oldPlaceWindow:] + 1551
    20  AppKit                              0x00007fff91c5b7bb -[NSWindow _setFrameCommon:display:stashSize:] + 1948
    21  AppKit                              0x00007fff91c5b019 -[NSWindow setFrame:display:] + 60
    22  AppKit                              0x00007fff91cab9db -[NSWindow(NSWindowResizing) _resizeWithEvent:] + 1223
    23  AppKit                              0x00007fff91cab4af -[NSTitledFrame mouseDown:] + 187
    24  AppKit                              0x00007fff91cab3c1 -[NSThemeFrame mouseDown:] + 626
    25  AppKit                              0x00007fff91c2b66e -[NSWindow sendEvent:] + 6280
    26  AppKit                              0x00007fff91bc3f19 -[NSApplication sendEvent:] + 5665
    27  AppKit                              0x00007fff91b5a42b -[NSApplication run] + 548
    28  AppKit                              0x00007fff91dd852a NSApplicationMain + 867
    29  MyApplication                         0x0000000100001e42 main + 34
    30  MyApplication                         0x0000000100001e14 start + 52
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-12-08 08:45:39

发现这是一种奇怪的做法。

Cocoa With Love 有一个很好的教程!

Found out that it was a weird way to do it.

Cocoa With Love had a nice tutorial!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文