【问题标题】:How to resize an extra box with disclosure triangle in Cocoa?如何在 Cocoa 中调整带有显示三角形的额外框的大小?
【发布时间】:2011-06-04 18:49:39
【问题描述】:

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

【问题讨论】:

    标签: cocoa macos window resize disclosure


    【解决方案1】:
    - (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;
        }
    

    【讨论】:

    • 你的意思是盒子的尺寸完全一样? (调整大小是您所要求的全部。)或者是框和/或其他控件最终处于错误位置的问题?如果是这样,您还需要调整原点 Ys,和/或在 IB 中设置顶部/底部支柱。
    • 对不起,我的问题不是很清楚,这就是您可能误解的原因。我真的让它工作了。但是我想在单击显示三角形时调整窗口大小,以便“额外框”可以出现在额外的窗口空间中。
    • 嗯,我的评论也不是很清楚。它实际上是在代码中调整大小的窗口,而不是框。 (这是有道理的。)所以现在一切正常了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多