• 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: Views, frames, and bounds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Views, frames, and bounds


  • Subject: Re: Views, frames, and bounds
  • From: DKJ <email@hidden>
  • Date: Sun, 19 Oct 2008 06:08:23 -0700

I did read the section of the documentation you mentioned, but so far it hasn't helped.

I'll show you some of the code I was playing with. I'm just not understanding why I'm getting the results I do.

I used IB to create a subview in a window, by dragging a custom layout view from the Library. I then set its class to MyView.

In MyView I have this:

	- (void)drawRect:(NSRect)rect {
		[[NSColor redColor] set];
		[NSBezierPath strokeRect:[self bounds]];
	}

When I run the code I get a nice red rectangle in the window, just where I expected it. But when I replace "bounds" with "frame", I get nothing.

That's the first puzzle. Maybe if I can understand what's happening here, the other puzzles will be resolved too!

dkj


On 18 Oct, 2008, at 22:06, Jamie Hardt wrote:

Do make sure you've read this: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/Coordinates/chapter_3_section_3.html#/ /apple_ref/doc/uid/TP40002978-CH10-SW9


The -frame and -bounds are two properties of an NSView, both rectangles. The frame is the the position of the view within its superview, thus, if you add a subview "B" to a view "A" and make it's rect {0,0,100,100}, it'll be a 100x100 box in the lower-left corner of "A". The bounds give the visible rectangle of the NSView in its own coordinate system; by default it has an origin of (0,0) and the same dimensions as the frame you gave when you initialized it, but it can be modified later. Thus, the bounds of view "B" can be {0,0,200,100} and this would cause the content of view "B" to be scrunched 2x from left to right.

When you give drawing commands in drawRect, all coordinates you give are with regard to the *bounds* of the view. SO, if you took the hypothetical view "B" above and stroked from (0,0) to (100,0), the line would only go halfway across the view (50 pixels), as its bounds.size.width are 2x of its frame.size.width.

Hope this helps. Post your code, as you might have the rects all right but may be doing something else incorrectly.

_______________________________________________

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


  • Follow-Ups:
    • Re: Views, frames, and bounds
      • From: Andy Lee <email@hidden>
    • Re: Views, frames, and bounds
      • From: Graham Cox <email@hidden>
References: 
 >Views, frames, and bounds (From: DKJ <email@hidden>)
 >Re: Views, frames, and bounds (From: Jamie Hardt <email@hidden>)

  • Prev by Date: Re: what do you use to make icons and similar?
  • Next by Date: Re: Passing Variables to AppleScript
  • Previous by thread: Re: Views, frames, and bounds
  • Next by thread: Re: Views, frames, and bounds
  • Index(es):
    • Date
    • Thread