NSWindow restorable not always working

只谈情不闲聊 提交于 2019-12-01 01:53:23

问题


I have checked the restorable option on my NSWindow When I move my application and change its size and close/reopen my application it sets the window size and position to the last size and position

but this doesn't happen on every computer where i test it. it only happens to a few computers

they don't have special settings regarding the resume.

Does anybody have any experience with this?


回答1:


But this doesn't happen on every computer where I test it. It only happens to a few computers. They don't have special settings regarding the resume.

Actually, they do. Take a look into the System Preferences > General pane. There should be an option named “Close windows when quitting an application” which is responsible for the restoration behavior. Additionally, in OS X Mountain Lion, Apple changed default behavior and now the app restores its state only when you quit using Command-Option-Q.

So, you probably should check which OS X version is installed on another Mac, and which preference is selected in the General pane. Hope this helps!




回答2:


One thing you should know is that checking the "Restorable" option in IB only changes a window property. The actual restoring and saving is in your hands.

First, you have to conform to the NSWindowDelegate protocol and implement the -window:willEncodeRestorableState:state and -window:didDecodeRestorableState: methods that encode and decode your window properties (For example your windows frame, which you obviously get by calling [myWindow frame]).

You also need to conform to the NSWindowRestoration protocol and implement +restoreWindowWithIdentifier:state:completionHandler:. (make sure you set your class to restoration class, with the setRestorationClass method)

For additional, more in depth, information, you can visit this Apple Documentation document here.




回答3:


If all you want is to restore the window's frame use setFrameAutosaveName:.

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/WinPanel/Tasks/SavingWindowPosition.html



来源:https://stackoverflow.com/questions/12779681/nswindow-restorable-not-always-working

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