How to show an NSWindow as sheet at specific locat

2019-08-04 14:12发布

问题:

I have a window like this, having 3 subviews, each one of them has button. On click of those- I need to show sheet.

By using this code, sheet comes in centre of the window.

- (IBAction)closeSubWindow:(id)sender{
    [NSApp endSheet:self.subWindow];
    [self.subWindow orderOut:nil];

}

- (IBAction)showSubWindow:(id)sender {
    [NSApp beginSheet:self.subWindow
       modalForWindow:self.window
        modalDelegate:self
       didEndSelector:nil
          contextInfo:nil];
}

Is there any option or way to show the sheet at specific co-ordinates?

EDIT:

My current implementation is by using NSPopover. Can I make this NSPopover to animate like sheet?

回答1:

Take a look at the NSWindow delegate method -window:willPositionSheet:usingRect:



回答2:

A sheet is per definition that what you see. So no, there is no way to place it at a different position. You could create an own implementation, but maybe it is better in your situation not to use a sheet but e.g. an NSPopover. This is availabe since OSX 10.7 and a great means to have a temporary view for displaying/entering values. By using the transient (or semi-transient) style the framework takes care for managing the display (automatically hiding the popover when no longer needed). Of course you can also have an OK button on it to commit changes.

The popover is also kinda modal, just like the sheet, so, functionally they are quite similar, but you have more freedom regarding its position.