Last active
April 21, 2017 14:13
-
-
Save udondan/1960409b8f17c0d3d6ff to your computer and use it in GitHub Desktop.
Swift controller for a modal window / sheet; see http://acapio.de/xcode/2014/07/12/swift_set_modal_window.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
class MyModalWindowController: NSWindowController { | |
var mainW: NSWindow = NSWindow() | |
override init() { | |
super.init() | |
} | |
override init(window: NSWindow!) { | |
super.init(window: window) | |
//Initialization code here. | |
} | |
required init?(coder: (NSCoder!)){ | |
super.init(coder: coder); | |
} | |
override func windowDidLoad() { | |
super.windowDidLoad() | |
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. | |
} | |
//method called to display the modal window | |
func beginSheet(mainWindow: NSWindow){ | |
self.mainW = mainWindow | |
NSApp.beginSheet(self.window!, modalForWindow: mainWindow, modalDelegate: self, didEndSelector:nil, contextInfo: nil) | |
} | |
//method called, when "Close" - Button clicked | |
@IBAction func btnClicked(sender: AnyObject) { | |
self.endSheet(); | |
} | |
//method called to slide out the modal window | |
func endSheet(){ | |
NSApp.endSheet(self.window!) | |
self.window!.orderOut(mainW) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. You should update it to use NSWindow beginsheet.