Re: Scrollers on custom view appearing but not disappearing
Re: Scrollers on custom view appearing but not disappearing
- Subject: Re: Scrollers on custom view appearing but not disappearing
- From: Quincey Morris <email@hidden>
- Date: Fri, 29 Feb 2008 22:33:17 -0800
On Feb 29, 2008, at 21:31, Steve Weller wrote:
-(void)frameDidChangeNotification:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
NSRect frame = [[self superview] frame];
NSSize cSize;
cSize = [self canvasSize];
// Use the larger dimensions of the canvas and the superview
if(frame.size.width > cSize.width)
cSize.width = frame.size.width;
if(frame.size.height > cSize.height)
cSize.height = frame.size.height;
[self
setFrame:NSMakeRect
(frame.origin.x,frame.origin.y,cSize.width,cSize.height)];
// NSLog(@"%f %f",newSize.width, newSize.height);
NSNotificationCenter *center = [NSNotificationCenter defaultCenter] ;
[center addObserver: self
selector: @selector(frameDidChangeNotification:)
name: NSViewFrameDidChangeNotification
object: self];
}
This figures out the rectangle that encloses both the canvas and the
superview's frame and makes my custom view's frame equal to that.
The only remaining thing to fix is that the lower left point is
always shown in the view, when I actually want the center point to
be shown. So I have to shift the frame origin as part of the
calculation.
A couple of small points:
-- It's not quite correct to use the superview's frame to calculate a
view's frame, since they are in different coordinate systems. You
really should use [[self superview] bounds], which is in the same
coordinate system as [self frame].
The problem is harmless in this case, because the superview is a
NSClipView, which happens to keep its frame coordinate system
synchronized with that of view it contains, but this is not generally
true of view-superview geometry.
-- If you want to refer to the clip view, [[self enclosingScrollView]
contentView] is more correct than [self superview]. The fact that
they're the same thing is an implementation detail. (But if you're
going to pretend not to know they're the same you really should do an
explicit coordinate conversion when combining their dimensions.)
-- As someone suggested on this list a few weeks ago, it's perhaps
marginally more elegant to use [self visibleRect] instead of the clip
view bounds. Although the purpose of the clip view is to manage the
visible rect of the view it contains, using the visible rect directly
means you don't have to build in knowledge of that implementation
detail. And there's no coordinate conversion needed.
_______________________________________________
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