Re: How to Translate iOS UIView Point to Mac NSView


Keary Suska
 

Or have your subclass implement -isFlipped to return YES.

On Aug 30, 2017, at 9:30 AM, Glenn L. Austin <glenn@...> wrote:

Mac uses bottom-left for the origin, which is why everything is "flipped in the Y direction".

You *can* do the calculation to move the origin to top-left and scale the transform in the opposite Y direction, but it's probably just as easy to "re-orient" yourself to bottom-left on macOS.

--
Glenn L. Austin, Computer Wizard, AustinSoft.com

On Aug 30, 2017, at 4:14 AM, Dave <dave@...> wrote:

Hi,

I’m converting some Manual Layout code from iOS to Mac.

I’m overriding “layout” in my class, it calculates and sets the Frame Rect for all its subviews. This works ok on Mac, except, as expected, everything is flipped in Y. I’m now trying to figure out how to flip the Y Coordinate.

Given that I have calculated the Frame Rect of a subview correctly, I’m then doing this:

myCalculatedFrameRect = the top, left Rectangle

myRect.origin.y = self.frame.size.height - myCalculatedFrameRect.origin.y;

[mySubview setFrame: myRect];

Which doesn’t work!

self in this case is the View I’m laying out, e.g. the superview of the subview,

What magic do I need to make this work? I was wondering if I should “flip” the View with the “isFlipped” method, but I’m not sure what other problems this might cause and would rather just flip the Coordinate in the layout method…..

All the Best
Dave

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

Join cocoa@apple-dev.groups.io to automatically receive all group messages.