[SOLVED] Re: Remembering the state of an NSScrollView?
[SOLVED] Re: Remembering the state of an NSScrollView?
- Subject: [SOLVED] Re: Remembering the state of an NSScrollView?
- From: Nick Zitzmann <email@hidden>
- Date: Fri, 9 Feb 2007 14:27:23 -0700
On Feb 9, 2007, at 9:21 AM, Dominik Pich wrote:
b) you might want to save the visibleRect's origin?!
Dont know if its any goood but worth a try, I'd say :)
Someone off-list gave me the hint that lead me to a solution. Just in
case anyone bumps into this in the archives, this appears to work:
@implementation NSView (Normalization)
- (NSRect)normalizedVisibleRect
{
NSRect visibleRect = [self visibleRect];
NSRect bounds = [self bounds];
NSRect normalizedVisibleRect;
normalizedVisibleRect.origin.x = (visibleRect.origin.x-
bounds.origin.x)/bounds.size.width;
normalizedVisibleRect.size.width = visibleRect.size.width/
bounds.size.width;
normalizedVisibleRect.origin.y = (visibleRect.origin.y-
bounds.origin.y)/bounds.size.height;
normalizedVisibleRect.size.height = visibleRect.size.height/
bounds.size.height;
return normalizedVisibleRect;
}
- (void)scrollNormalizedRectToVisible:(NSRect)normalizedVisibleRect
{
NSRect bounds = [self bounds];
NSRect visibleRect;
visibleRect.origin.x = bounds.origin.x
+bounds.size.width*normalizedVisibleRect.origin.x;
visibleRect.size.width =
normalizedVisibleRect.size.width*bounds.size.width;
visibleRect.origin.y = bounds.origin.y
+bounds.size.height*normalizedVisibleRect.origin.y;
visibleRect.size.height =
normalizedVisibleRect.size.height*bounds.size.height;
[self scrollRectToVisible:visibleRect];
}
@end
Then we can archive the result of -normalizedVisibleRect, and
unarchive it later and plug it into -scrollNormalizedRectToVisible:,
and everything works.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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