On Jun 16, 2011, at 14:57, Leonardo wrote:

> I would like to reach the same effect as UIScrollView.pagingEnabled, but on
> an NSScrollView. Can that be done?
> 
> If not, which technique should I use?
> I thought to deal with NSAnimationContext to move the scrollView's document
> with scrollPoint: when a scrolling ends (the finger stops dragging on the
> track-pad). Am I on the right way?

NSScrollView is not designed to have this behavior, so you'll have to do the 
work.

The basic approach is to have (say) your window controller monitor the scroll 
view's clip view's frame- and bounds-changed notifications. When you receive 
these notifications, you examine the relationship between the "clip" view 
bounds and the "document" (i.e. enclosed) view frame, and adjust the 
relationship to align the two views however you want.

To detect when scrolling "ends", you can use a well-known trick. When you see a 
notification, don't perform the scrolling adjustment immediately, but schedule 
it for "later" using 'performSelector: ... afterDelay: 0'. Since you don't want 
multiple deferred adjustments to get queued, you first cancel any pending ones 
with one of the 'cancelPrevious...' or 'cancelPerform...' methods, just before 
invoking 'performSelector:...'. That way, the last one "wins".

If you want to have this adjustment animate, you should be able to use the 
appropriate view's animator or NSViewAnimation to move the document view frame.

The only difficulty I can think of is if Lion's trackpad gesture-based 
scrolling itself has some animation built into it (e.g. an iOS-like "bounce"). 
In that case you might have some trouble trying to integrate your animation 
with the built-in one.

However, given that all of this is not expected Mac scroll view behavior, 
unless you have a *very* compelling need for it, I'd recommend you don't do it. 
NSScrollView responds to the Page Up and Page Down keys for paging. Why limit 
the user to where you think the page boundaries are?


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to