views:

96

answers:

2

How can I flip the coordinate system of an NSWindow? I know it has a Content View, but how can I flip the coordinate system of that specific View which is of type NSView?

In a sub-view of my NSWindow's Content View I flip the coordinate system by subclassing NSView, placing that in my window, and in that subclassed NSView I implement method isFlipped to return YES. No idea how I could have NSWindow make it's content view out of "MyFlippedSubclassedNSView"

A: 

Looks like you want -[NSView setBoundsOrigin:].

Dave DeLong
I don't see how that will solve it; I can make my origin be the upper-left of my view instead of the lower-left, but if I draw a button at "0, 20, buttonwidth, buttonheight" I'm going to draw it 20 pixels above the top of my view right?? I'm looking to have this 0, 20 example draw 20 pixels below the upper left of my view.
Nektarios
Nektarios: Correct. Changing the origin is not enough. You must also scale the co-ordinate system into the opposite direction.
Peter Hosey
+3  A: 

You can't change the internal co-ordinate system of an NSWindow. The closest you can get is to have a flipped view as the content view.

Chances are you don't actually need a flipped content view or window, though. What are you actually trying to accomplish by flipping the co-ordinate system?

No idea how I could have NSWindow make it's content view out of "MyFlippedSubclassedNSView"

Do that. Make a MyFlippedSubclassedNSView instance, and set it as the content view.

Even easier is to do it in IB: Select the window's content view, hit ⌘6 (Identity), and set the view's class to MyFlippedSubclassedNSView.

Peter Hosey
Well that's perfect. Thank you! I'm not sure why that wasn't obvious to me.I don't "need" a flipped view but it will make my life a lot easier. I'm going to be doing dynamic layout programmatically of a lot of views and the list naturally grows top-to-bottom. Since I'm tracking all coordinates of my view placements manually, this will make my arithmetic make a lot more sense to me.
Nektarios