cocoamacoswindowresizedisclosure

How to resize an extra box with disclosure triangle in Cocoa?


How to resize an extra box with disclosure triangle in Cocoa?

- (IBAction)disclosureTriangleClicked:(id)sender {
    NSWindow *window =[sender window];
    NSRect frame = [window frame];
    [otherBox frame].size.height +14;
    switch([sender state]) {
        case NSOnState:
            [otherBox setHidden:NO];
            //Must resize!
            break;
        case NSOffState:
            [otherBox setHidden:YES];
            //Must resize!
            break;
        default:
            break;
    }

Solution

  • - (IBAction)disclosureTriangleClicked:(id)sender {
        NSWindow *window =[sender window];
        NSRect frameWinOld = [window frame];
        CGFloat heightWinOld = frameWinOld.size.height;
        NSRect frameOtherBox = [otherBox frame];
        CGFloat heightOtherBoxWithMargin = frameOtherBox.size.height +14;
        switch([sender state]) {
            case NSOnState:
                [window setFrame:NSRectMake(frameWinOld.origin.x, frameWinOld.origin.y, frameWinOld.width, frameWinOld.height + heightOtherBoxWithMargin) display:YES];
                [otherBox setHidden:NO];
                break;
            case NSOffState:
                [window setFrame:NSRectMake(frameWinOld.origin.x, frameWinOld.origin.y, frameWinOld.width, frameWinOld.height - heightOtherBoxWithMargin) display:YES];
                [otherBox setHidden:YES];
                break;
            default:
                break;
        }