Странное поведение на splitView: (NSSplitView *) splitView resizeSubviewsWithOldSize: (NSSize) oldSize в ОС x Lion - PullRequest
0 голосов
/ 24 августа 2011

Я создаю приложение с двумя разделенными представлениями (одно разделенное представление в разделенном справа виде) Но у меня возникают проблемы после обновления до OS X Lion.

Приложение аварийно завершает работу при использовании действия изменения размера в правом нижнем углу, т.е. при одновременном изменении высоты и ширины.

Когда я закомментирую этот код, странное поведение исчезнет, ​​но тогда разделенное представление рухнет, чего я не хочу.

(- (BOOL) splitView: (NSSplitView *) splitView canCollapseSubview: (NSView *) подпредставление) возвращает 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
)

1 Ответ

0 голосов
/ 25 августа 2011

Узнал, что это был странный способ сделать это.

Какао с любовью был хороший учебник!

...