Best practice for resizing animation windows using ToolBar on Cocoa

I am wondering how best to resize the window when changing the Toolbar.

I try to get this effect (animated) when the selected toolbar option changes.

The size of the window responds to the action of the toolbar.

Any ideas?

Thanks for the help!:)

+4
source share
2 answers

Here is my commonly used method:

After you click on a new toolbar item, first get the frame size of the new subview, and then change the frame of the window with the animation.

Demo (just change the height, but you can add support for changing the width):

- (void)switchToTabView:(NSView *)settingView withAnimation:(BOOL)animation
{
    NSView *windowView = self.window.contentView;
    for (NSView *view in windowView.subviews) {
        [view removeFromSuperview];
    }

    CGFloat oldHeight = windowView.frame.size.height;

    [windowView addSubview:settingView];
    CGFloat newHeight = settingView.frame.size.height;

    CGFloat delta = newHeight - oldHeight;

    NSPoint origin = settingView.frame.origin;
    origin.y -= delta;
    [settingView setFrameOrigin:origin];

    NSRect frame = self.window.frame;
    frame.size.height += delta;
    frame.origin.y -= delta;
    [self.window setFrame:frame display:YES animate:animation];
}
+3
source

@GoKu. , . "win".

:

- (void)updateView:(int)tag{
    [[_ourViewController view] removeFromSuperview];
    if (tag==0) {
        self.ourViewController = [[UserView alloc] initWithNibName:@"UserView" bundle:nil];
    } else if (tag==1){
        self.ourViewController = [[ComputerView alloc] initWithNibName:@"ComputerView" bundle:nil];
    }

    NSView *newView = _ourViewController.view;

    NSRect windowRect = _win.frame;
    NSRect currentViewRect = newView.frame;

    windowRect.origin.y = windowRect.origin.y + (windowRect.size.height - currentViewRect.size.height);
    windowRect.size.height = currentViewRect.size.height;
    windowRect.size.width = currentViewRect.size.width;

    [self.win setContentView:newView];
    [self.win setFrame:windowRect display:YES animate:YES];
}

Thanx!

0

Source: https://habr.com/ru/post/1605861/


All Articles