如何在Cocoa中调整带有公开三角形的额外框?

时间:2011-06-04 18:49:39

标签: cocoa macos window resize disclosure

如何在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;
    }

1 个答案:

答案 0 :(得分:2)

- (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;
    }