初始大小调整后无法调整NSPanel的大小

时间:2013-04-12 15:31:42

标签: resize nswindow nspanel

我想在用户解散某个项目时调整NSPanel的大小。我最初可以完美地调整它的大小:

    [super awakeFromNib];
_mustNotAutoSize=FALSE;
// Make a fully skinned panel
NSPanel *panel = (id)[self window];
[panel setAcceptsMouseMovedEvents:YES];
[panel setLevel:NSPopUpMenuWindowLevel];
[panel setOpaque:NO];
[panel setBackgroundColor:[NSColor clearColor]];

[panel setOpaque:YES];
[panel setBackgroundColor:[NSColor blueColor]];

// Resize panel
NSRect panelRect = [[self window] frame];
int nR=[self numberOfReminders];
float desiredHeight=nR*(52.0)+BORDER_INSET*2+ARROW_HEIGHT+ 22.0;
if(desiredHeight>POPUP_HEIGHT)desiredHeight=POPUP_HEIGHT;
if(desiredHeight<50.0)desiredHeight=50.0;
panelRect.size.height = desiredHeight;

[[self window] setFrame:panelRect display:NO];

但是当我稍后减少项目数量并调用调整大小功能时,它不起作用:

    - (void)sizePanelBasedOnReminders
{
    NSWindow *panel = [self window];
    NSRect panelRect = [panel frame];
    NSLog(@"Panel height is starting at: %f",panelRect.size.height);
    int nR=[self numberOfReminders];
    float desiredHeight=nR*(52.0)+BORDER_INSET*2+ARROW_HEIGHT+ 22.0;
    if(desiredHeight>POPUP_HEIGHT)desiredHeight=POPUP_HEIGHT;
    if(desiredHeight<BORDER_INSET*2+ARROW_HEIGHT+ 22.0)desiredHeight=BORDER_INSET*2+ARROW_HEIGHT+ 22.0;
    panelRect.size.height = desiredHeight;
    NSLog(@"Panel height is changing to: %f",panelRect.size.height);

    [panel setFrame:panelRect display:YES];

}

有什么想法吗?

2013-04-12 11:27:47.997 LoveBug[44016:303] Deleted row is: 0
2013-04-12 11:27:47.997 LoveBug[44016:303] Panel height is starting at: 400.000000
2013-04-12 11:27:47.998 LoveBug[44016:303] Numberofitems called, return 6
2013-04-12 11:27:47.998 LoveBug[44016:303] Panel height is changing to: 352.000000
2013-04-12 11:27:48.628 LoveBug[44016:303] Sending 0
2013-04-12 11:27:48.629 LoveBug[44016:303] Deleted row is: 0
2013-04-12 11:27:48.629 LoveBug[44016:303] Panel height is starting at: 352.000000
2013-04-12 11:27:48.630 LoveBug[44016:303] Numberofitems called, return 5
2013-04-12 11:27:48.630 LoveBug[44016:303] Panel height is changing to: 300.000000
2013-04-12 11:27:49.156 LoveBug[44016:303] Sending 0
2013-04-12 11:27:49.156 LoveBug[44016:303] Deleted row is: 0
2013-04-12 11:27:49.157 LoveBug[44016:303] Panel height is starting at: 300.000000
2013-04-12 11:27:49.157 LoveBug[44016:303] Numberofitems called, return 4
2013-04-12 11:27:49.158 LoveBug[44016:303] Panel height is changing to: 248.000000

0 个答案:

没有答案