• 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: How to properly flip a UIView's coordinate system
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to properly flip a UIView's coordinate system


  • Subject: Re: How to properly flip a UIView's coordinate system
  • From: Dave <email@hidden>
  • Date: Sun, 22 Sep 2013 12:20:45 +0100

On 21 Sep 2013, at 21:38, Markus Spoettl <email@hidden> 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@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: How to properly flip a UIView's coordinate system
      • From: Kyle Sluder <email@hidden>
    • Re: How to properly flip a UIView's coordinate system
      • From: David Rowland <email@hidden>
References: 
 >How to properly flip a UIView's coordinate system (From: Markus Spoettl <email@hidden>)

  • Prev by Date: Re: CGImageRef as a property of a cocoa object
  • Next by Date: Re: How to properly flip a UIView's coordinate system
  • Previous by thread: Re: How to properly flip a UIView's coordinate system
  • Next by thread: Re: How to properly flip a UIView's coordinate system
  • Index(es):
    • Date
    • Thread