When a popover is displaying how can I make its size variable depending on condition check? Is this functionality supported or not when working with a popover?
Here is my sample for changing frame size:
CGFloat newHeight = 200;
NSRect newFrame = [parentView frame];
newFrame.size.height = newHeight;
NSView* childView = someView;
[parentView setFrame:newFrame];
[self.view addSubview:childView];
You need to change the
popupwindow.contentViewControllerproperty of theNSPopoverto a newNSViewControllerwith a different-sized view.That is, resizing the view’s frame will only result in weird drawing problems. To get the popover window to change size, the
contentViewControllermust be changed.Ideally, you would set up a new view controller which is essentially a copy of your existing
NSViewController, but containing a view that is taller/shorter. But in the worst-case scenario, you can do something like this:In my testing, this resulted in the popover beginning a shrink animation (because of being set to the temp view controller), then growing to its new size.