• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Subview frames and bounds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subview frames and bounds


  • Subject: Re: Subview frames and bounds
  • From: Patrick Mau <email@hidden>
  • Date: Mon, 03 Nov 2008 14:51:43 +0100

On 03.11.2008, at 14:23, DKJ wrote:

I'm still puzzled by frames and bounds. I put this in the drawRect: of MyView:

	[[NSColor redColor] set];
	NSRectFill( self.frame );
	[[NSColor blueColor] set];
	NSFrameRect( self.bounds );

I put this in the awakeFromNib of my controller:

	NSRect r = NSMakeRect( 10.0, 10.0, 200.0, 200.0 );
	MyView *mv = [[MyView alloc] initWithFrame:r];
	[[theWindow contentView] addSubview:mv];

The blue bounds rectangle is drawn just where I would expect: inset 10 pixels from the lower left corner of the window. But the red frame rectangle is inset another 10 pixels from the lower left corner of the blue bounds rectangle.

When I set the origin of r to (0.0, 0.0), the red and blue rectangles coincide.

What's happening here?

You create a view defining its frame. In your example the frame is (10,10,200,200) and your bounds would be (0,0,200,200), because you did not change the origin.

Drawing always takes place within the bounds, the frame is irrelevant.

Therefore the red rectangle is drawn with in offset of 10 pixels from inside the bounds,
meaning (10,10,200,200) in 'bounds', but (20,20,200,200) in 'frame' coordinates.


This sentence did not make sense ;) Just keep in mind that drawing always happens in the
'bounds' coordinate system and the 'frame' represent placement (and scaling of these bounds.


Regards,
Patrick
_______________________________________________

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


References: 
 >Subview frames and bounds (From: DKJ <email@hidden>)

  • Prev by Date: Subview frames and bounds
  • Next by Date: Re: Subview frames and bounds
  • Previous by thread: Subview frames and bounds
  • Next by thread: Re: Subview frames and bounds
  • Index(es):
    • Date
    • Thread