NSTextView actions
NSTextView actions
- Subject: NSTextView actions
- From: Randall Meadows <email@hidden>
- Date: Thu, 30 Oct 2008 19:23:13 -0600
OK, last text-related question of the day (I promise, only because I'm
calling it a day after I send this)...
I have an NSTextView, in an NSScrollView, (loaded from a nib) that I
embed in a custom view at runtime; I also draw a reflection of that
custom view.
I figured out how to do a "live" reflection, where the reflection
updates in real-time as the scroll bar is dragged around. However,
it's only a partial solution, and while it works (partially), it's
butt-ugly, and I'm guessing there must be a more elegant way to do
this than what I'm doing.
To do the live-drag reflection, I cache the original target/action of
the scroller, and stuff my own target/action into it instead.
originalAction = [verticalScroller action];
originalTarget = [verticalScroller target];
[verticalScroller setTarget:self];
[verticalScroller setAction:@selector(scrollReflection:)];
In my action, I call
[originalTarget performSelector:originalAction withObject:sender];
to handle the knob drag itself, and then update my reflection view.
This works great. As long as I only drag the knob in the scroll bar.
If I page or use the arrow keys, my action doesn't get called (I'm not
using the scroll arrows themselves, so I don't know what happens in
that case).
I looked for a notification or a delegate method on both NSScrollView
and NSTextView, but I didn't find anything that seemed to tell me "Hey
you, my contents just changed position!" so that I can update my
reflection in all cases.
Hmmm....wait a minute. I think I see what's happening...
When I hit, for example, the Page Up area of the scroll bar, it
animates to it's new position; my reflection updates only a very small
portion of this change. It doesn't at all when I hit the Page Up key,
though. Is the animation process taking long enough that the very
next line of code is executed before it's done, and therefore I don't
capture any (or most) of the scroll? If so, is there some
deterministic way I can tell when the scroll animation has completed,
so I can update my view?
Thanks!
randy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden