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