如何在目标C中的Xcode 6.3 OS X10.10中制作NsPopover

时间:2015-10-01 18:13:14

标签: macos nspopover

我是一名新开发者,我正在尝试按钮点击开发Nspopover,但我没有获得相关资源,所以我应该如何在XCode 6.3中完成。

1 个答案:

答案 0 :(得分:1)

https://developer.apple.com/library/mac/samplecode/Popover/Listings/MyWindowController_m.html

顺便说一下,如果你自己搜索“nspopover site:developer.apple.com/library/mac/samplecode”,它会更快

@property (weak) IBOutlet NSViewController *popoverViewController;

// -------------------------------------------------------------------------------
//  showPopoverAction:sender
// -------------------------------------------------------------------------------
- (IBAction)showPopoverAction:(id)sender
{
    [self createPopover];

    NSButton *targetButton = (NSButton *)sender;

    // configure the preferred position of the popover
    NSRectEdge prefEdge = popoverPosition.selectedRow;

    [self.myPopover showRelativeToRect:[targetButton bounds] ofView:sender preferredEdge:prefEdge];
}


// -------------------------------------------------------------------------------
//  createPopover
// -------------------------------------------------------------------------------
- (void)createPopover
{
    if (self.myPopover == nil)
    {
        // create and setup our popover
        myPopover = [[NSPopover alloc] init];

        // the popover retains us and we retain the popover,
        // we drop the popover whenever it is closed to avoid a cycle
        //
        // use a different view controller content if normal vs. HUD appearance
        //

        self.myPopover.contentViewController = popoverViewController;

        // AppKit will close the popover when the user interacts with a user interface element outside the popover.
        // note that interacting with menus or panels that become key only when needed will not cause a transient popover to close.
        self.myPopover.behavior = NSPopoverBehaviorTransient;
    }
}