how to move a popover along with slider button

296 Views Asked by At

I have a custom slider for volume and I want the current value of the slider to be displayed in a popover what I already have so far, see picture below.

Unfortunately at the moment the popover is static in the middle of the slider.

Any idea how I can make the popover to move along with the slider button?

This is what I have so far:

- (IBAction)showPopover:(id)sender {

   volumeSetting = [sender intValue];
   [volumeLabel setStringValue:[NSString stringWithFormat:@"%i",volumeSetting]];
   [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge ];

}

enter image description here

2

There are 2 best solutions below

0
On

Instead of using the bounds of the sender determine rather where the slider is at this moment and create a small rectangle from the position (NSPopover uses this to center at its borders depending on preferred size). Unfortunately, this will not animate the popover. It will just jump from one position to the next.

0
On