0

My NSSavePanel is behaving strangely. Whenever I click on it (any area that normally allows you to drag the window around), it moves down the screen a few pixels. This only happens when I click on empty space like the large empty area of the toolbar.

Here is the relevant code:

@IBAction func saveThisImageAction(sender: AnyObject) {
    dispatch_async(dispatch_get_main_queue()) {
        let savePanel = NSSavePanel()
        savePanel.nameFieldStringValue = self.thisPost.id + ".png"

        let result = savePanel.runModal()

        if result == NSFileHandlingPanelOKButton {
            let exportedFileURL = savePanel.URL!
            guard let lastImagePath = self.persistentStorage.stringForKey("lastImagePath")
                else { NSLog("Error getting last post ID from persistent storage."); return }
            let imageData = NSData(contentsOfFile: lastImagePath)!
            imageData.writeToURL(exportedFileURL, atomically: true)
        }
    }
}

Why is this happening, and how can I fix it? For bonus points, the NSSavePanel doesn't become the active window when it appears. If anyone know how to fix that as well, it would be appreciated.

yesthisisjoe
  • 1,987
  • 2
  • 16
  • 32
  • Remove `dispatch_async(dispatch_get_main_queue())`? – Willeke May 03 '16 at 13:58
  • @Willeke Thanks, but that hasn't worked for me. – yesthisisjoe May 03 '16 at 13:59
  • This code is correct. You probably have an issue with autolayout somewhere. – Eric Aya May 03 '16 at 14:09
  • I don't use auto layout in the project at all! I'll try to run it on a fresh user account and see if this persists – yesthisisjoe May 03 '16 at 14:14
  • It's still a problem. When I made a new project with *just* a button that opens an NSSavePanel it worked fine. The NSSavePanel in that project looked a little different. The minimize/maximize buttons were separated from the actual content of the NSSavePanel into a bar across the screen (which also had the title text "Save"). In my project there is no such separation, and no title. The minimize/maximize buttons are part of the content. – yesthisisjoe May 05 '16 at 02:38

0 Answers0