0

私は .xib を持っていて、それには 1 つのウィンドウがNSToolbarあり、すべて同じ xib の一部である複数のカスタム ビューがあります。ツールバー アイコンをクリックすると、ビューが切り替わりますが、そのビューにあるボタンやその他のオブジェクトは表示されません。

両方のビューのサイズが異なり、ウィンドウが調整されているため、ビューが切り替わっていることはわかっています

ビューを切り替えるコード:

NSInteger tag = [sender tag];

NSView *view = [self viewForTag:tag];
NSView *previousView = [self viewForTag: currentViewTag];
currentViewTag = tag;
NSRect newFrame = [self newFrameForNewContentView:view];

[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.1];

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

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

[NSAnimationContext endGrouping];
4

1 に答える 1

0

最善の方法ではないかもしれませんが、よくわかりませんが、ビューを切り替える方法は次のとおりです。

#import "AppDelegate.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    self.firstSubView = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
    self.secondSubView = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];

    [self.customView addSubview: self.firstSubView.view];
    self.firstSubView.view.frame = self.customView.bounds;

    self.firstViewIsSelected = YES;
}

- (IBAction)viewSwitched:(id)sender {
    if (self.firstViewIsSelected) {
        [self.firstSubView.view removeFromSuperview];
        [self.customView addSubview: self.secondSubView.view];
        self.secondSubView.view.frame = self.customView.bounds;
    }
    else{
        [self.secondSubView.view removeFromSuperview];
        [self.customView addSubview: self.firstSubView.view];
        self.firstSubView.view.frame = self.customView.bounds;
    }
    self.firstViewIsSelected = !self.firstViewIsSelected;
}
于 2013-02-20T13:22:24.173 に答える