0

我有一个 MainMenu.xib 文件,我有一个名为“首选项”的窗口我还有四个不同高度的不同自定义视图。和该窗口上的工具栏。我已将每个工具栏项链接到 -(void) switchViews:(id)sender; 功能。视图已链接并且正在显示并且也在发生变化,但问题是如果我从一个视图更改为另一个视图,然后返回或更改为另一个视图,视图上的内容(即按钮、标签、复选框)继续向上移动,窗口仍然不断改变到正确的高度,但如果我切换足够多的时间,内容将从视图中消失。任何形式的帮助都会很有用。

http://imgur.com/bV3NHa0,zgJCacA http://imgur.com/bV3NHa0,zgJCacA#1

// FOR CHANGING VIEWS IN THE PREFERENCES WINDOW
- (IBAction)switchView:(id)sender {

long int tag = [sender tag];
NSView *view = [self viewForTag:tag];
NSView *previousView = [self viewForTag:currentViewTag];
currentViewTag = tag;

NSRect newFrame = [self newFrameForNewContentView:view];

[NSAnimationContext beginGrouping];

if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) {
    [[NSAnimationContext currentContext] setDuration:1.0];
}

[[[[self preferences] contentView] animator] replaceSubview:previousView with:view];
[[[self preferences] animator] setFrame:newFrame display:YES];

[NSAnimationContext endGrouping];

}

- (NSView *)viewForTag:(long int)tag {

  NSView *view = nil;
  switch (tag) {
    case 0:
        view = generalView;
        break;
    case 1:
        view = timesView;
        break;
    case 2:
        view = menubarView;
        break;
    case 3: default: view = aboutView;
        break;
  }
  return  view;
}

- (NSRect)newFrameForNewContentView:(NSView *)view {

NSWindow *window = [self preferences];
NSRect newFrameRect = [window frameRectForContentRect:[view frame]];
NSRect oldFrameRect = [window frame];
NSSize newSize = newFrameRect.size;
NSSize oldSize = oldFrameRect.size;

NSRect frame = [window frame];
frame.size = newSize;
frame.origin.y -= (newSize.height - oldSize.height);

return frame;
}
4

1 回答 1

0

对于您描述的问题并查看您的代码,我会开始怀疑这一行......

frame.origin.y -= (newSize.height - oldSize.height);
于 2013-06-24T03:23:59.663 回答