如何将MAAttachedWindow的视图与可见的窗口交换?
defaultViewController = [DefaultViewController alloc] initWithNibName:@"DefaultView" bundle:nil];
attachedWindow = [[MAAttachedWindow alloc] initWithView:[defaultViewController view]
attachedToPoint:point
inWindow:nil
onSide:MAPositionBottom
atDistance:25.0];
我如何交换另一个视图控制器的视图?
答案 0 :(得分:1)
经过一夜好眠,花了5分钟才弄清楚了!
NSViewController *vc = [[NSViewController alloc] initWithNibName:@"MainView"
bundle:nil];
view = vc.view;
[vc release];
// Setup firstViewController here, addSubview and set current = firstViewController.view
attachedWindow = [[MAAttachedWindow alloc] initWithView:view
attachedToPoint:pt
inWindow:nil
onSide:MAPositionBottom
atDistance:5.0];
然后在我的交换视图方法中,只需:
-(void)swapView
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
// Resize our host view
[view setFrameSize:secondViewController.view.frame.size];
// Replace the current view
[view replaceSubview:current with:secondViewController.view];
// Resize our attachedWindow
[attachedWindow setFrame:secondViewController.view.frame display:YES];
[secondViewController release];
[current release];
}