Thanks for the detailed reply, Conrad.
I may reconsider my plan of restoring the scroll position. It seemed like a 
nice function for my app, but maybe not essential.

J.

On 2011-12-03, at 11:26 AM, Conrad Shultz wrote:

> On 12/3/11 10:31 AM, James Maxwell wrote:
>> This may have a simple answer, but I can't seem to find it. I want my
>> document's scroll view to restore the scroll position when opening
>> from a file. The default behaviour seems to be to set it back to {0,
>> 0} (i.e., so that my document's view always returns to the upper-left
>> corner). Is there a simple way (a flag, maybe) to tell it to restore
>> to the last scroll position? If not, how do I add this behaviour?
> 
> NSScrollView will automatically encode and restore its scroll position
> as part of Lion window restoration.  I don't know of a way to do the
> same for file save/open.
> 
> To determine the "scroll position" manually you examine the bounds
> origin of the enclosed clip view; see the Scroll View Programming Guide
> (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/Scrolling.html)
> for details.
> 
> However, be sure to consider various issues before you set about
> implementing this:
> 
> 1) For most documents the scroll position is more of a view property
> than a model property, so it would likely be inappropriate to encode
> into the document.  Locally caching (by some means) the scroll position
> addresses this, but might lead the users to erroneously expect scroll
> position to be preserved if the document is opened elsewhere.  (Notably,
> Lion window restoration stores the view metadata in a separate location
> the local disk.)
> 
> 2) If the document is modified via a mechanism that is scroll position
> unaware (e.g. you are saving in a file format for which other editors
> are available), the cached scroll position can become out of sync with
> the underlying model.
> 
> 3) Scroll position can be window size dependent.  Suppose you are on a
> laptop with your app displayed on a large external display.  You save
> the document and cache the scroll position, then close the app.  Later,
> without the external display, you reopen the document.  OS X will
> automatically downscale the application window frame to fit the smaller
> screen, and resizing masks or auto-layout will kick in to shrink your
> scroll view.  This invalidates the cached scroll position, and could
> land the scroller in an inappropriate (or even invalid) location.
> 
> There are probably other "gotchas" that one could think of too.  So take
> care when making the decision whether to implement this feature, and if
> you choose to do so, consider the edge cases.
> 
> -- 
> Conrad Shultz
> 
> Synthetiq Solutions
> www.synthetiqsolutions.com

James B Maxwell
Composer/Doctoral Candidate
School for the Contemporary Arts (SCA)
School for Interactive Arts + Technology (SIAT)
Simon Fraser University

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to