On 21 Sep 2013, at 21:38, Markus Spoettl <[email protected]> wrote:

> Hi,
> 
>  I have a UIView on iOS that shares (a lot of) code with an NSView I have on 
> OSX. That code relies on a LLO (lower left origin) coordinate system and it's 
> not an option to change that.

I'm in a similar position, in fact I have a lot of code that is ULO based and a 
lot of code that is LLO based. If I has only a single wish that would enable me 
to change something about Cocoa it would be that it always ULO or as a second 
wish that iOS used LLO as well. 

I'd really like to know why LLO was chosen for the Mac in the first place, and, 
why in iOS they chose to do the opposite?

Anyone understand why/how this happened?

Also, given that you have code what is written for both systems, how have 
people dealt with this? In one iOS App I was working on there it was so hard to 
figure out which coordinate system was needed, I changed it to always use Top 
Left 0,0 as the origin.

I make an XXRect class, that held the rectangle in both formats and whenever 
one was changed it changed the other, like so:

typedef enum
        {
        NIRectTypeUI = 0,
        NIRectTypeCG
        } NIRectType;

@interface XXRect : NSObject 
{
NIRectType                                      mRectType;
NIRectDrawStatus                        mRectDrawStatus;
CGContextRef                            mCGContextRef;
CGRect                                          mUIRect;
CGRect                                          mCGRect;
}

@property (nonatomic)   XXRectType              pRectType;
@property (nonatomic)   CGRect                  pUIRect;
@property (nonatomic)   CGRect                  pCGRect;

- (id) initWithUIRect:(CGRect) theUIRect forContext:(CGContextRef) theCGContext;
- (id) initWithCGRect:(CGRect) theCGRect forContext:(CGContextRef) theCGContext;


XXRect myRect = [[XXRect alloc[ initWithUIRect(myUIRect,myContext];

This works quite well, but it's a bit klunky.

I find it really difficult to switch between LLO and ULO systems in my head and 
have spent ages trying to figure why something doesn't work and then ages 
trying to figure out how to fix it!

All the Best
Dave


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to