I have a NSPopover which contains a view (toolbarView). This toolbar consists of two buttons (button 1 and button 2). When button 1 is pressed, "showView1" method is activated and view1 is added below toolbarView. Similarly, when button 2 is pressed, "showView2" method is activated and view2 is add below toolbarView.
I store in activeView the view being shown below toolbarView, so that this view is always removeFromSuperview (toolbarView) when switching views.
The code works and you can switch views back and forth, however, there is flickering going on when you switch views. I have tried many things (mainly playing with setHidden on both views), but I can't get it to work without this annoying flickering. Is there any problem with the code? Should I rather put both views into a tabless tab view?
- (void)changeView:(NSView*)view {
[view setHidden:YES];
[_activeView setHidden:YES];
[_activeView removeFromSuperview];
CGRect toolbarRect = _toolbarView.frame;
toolbarRect.size = _toolbarInitSize;
NSLog(@"View [x: %f y: %f w: %f h: %f", view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
NSLog(@"Toolbar [x: %f y: %f w: %f h: %f", _toolbarView.frame.origin.x, _toolbarView.frame.origin.y, _toolbarView.frame.size.width, _toolbarView.frame.size.height);
toolbarRect.size.width = view.frame.size.width;
_toolbarView.frame = toolbarRect;
[_toolbarView addSubview:view];
[view setFrame:[_toolbarView bounds]];
// Move view down
CGRect rect = view.frame;
rect.origin.y -= toolbarRect.size.height;
view.frame = rect;
NSSize frameSize = self.popover.contentSize;
frameSize.width = toolbarRect.size.width;
frameSize.height = toolbarRect.size.height + view.frame.size.height;
self.popover.contentSize = frameSize;
[view setHidden:NO];
_activeView = view;
}
- (IBAction)showView1:(id)sender {
[self changeView:_view1];
}
- (IBAction)showView2:(id)sender {
[self changeView:_view2];
}