How to show an NSWindow as sheet at specific location

丶灬走出姿态 提交于 2020-01-15 11:40:19

问题


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.



来源:https://stackoverflow.com/questions/16275950/how-to-show-an-nswindow-as-sheet-at-specific-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!