On Tue, 14 Sep 2010 10:31:39 +1000, Gideon King <gid...@novamind.com> said:
>The first is that I am trying to make sure that I will be able to print what I have on my view, but this doesn't seem to be working. I tried creating a layer backed view, which in its drawRect: method fills the rect with red, and added a sub-layer that has an image drawn on it, and an opacity on that layer of 0.5. It draws my image over the red background, but when I try to print the view, it just prints the drawing that happened in the view itself and not the sub-layer. Printing is drawing by a view. The view that performs the printing needn't be the view seen on the screen. The view is handed a context at print time and told: draw into this! (That is what drawRect: is about.) Whatsoever the view does into that context, that is what is printed. Layers are an efficient way of presenting material on the screen and do not feature anywhere in the printing story I just told you. A view is not drawing its layer's sublayers in its drawRect; the layer draws itself (onto the screen). So if you want to portray on paper what the user saw on the screen, you'll need a view that knows how to draw that in its drawRect. If layers were involved in what the user saw on the screen, the view will have to know how to draw what those layers were drawing. >The second part of this is that I am a little confused by the documentation's statements about layer coordinate system. I want to be able to write the drawing code once and deploy both on Mac and maybe iOS later. The documentation says that UIView uses a flipped coordinate system and that therefore the root layer also has a flipped coordinate system. I tried making my view flipped, but its layer doesn't appear to be flipped. Does this mean that I have to apply a flipping transform to the root layer? > >It also says that layers you instantiate on iOS are flipped and on Mac are not, so I presume this means that for every layer I instantiate on MacOS, I have to apply a flip transform to get it to the state where I can use the same drawing for both platforms, right? (I am so used to drawing in flipped views, that that is the way I would want to work anyway). Basically what the docs are saying is that Mac and iOS have opposite y-directions by default, but not to worry because contexts on iOS have a transform applied so as to compensate. Thus, when you're drawing on iOS, you just assume that the context you're drawing into has a y-direction that grows downwards, and you're generally right. If you do get a y-direction impedance mismatch, you'll know it, because things will be upside down. :) This usually arises only when drawing into an offscreen image and then drawing that image into a context (and even then, on iPhone, it only arises if you use CGImageRef, because a UIImage's context is also transformed to compensate). On Mac, flippedness issues can also arise when drawing text, because text grows down but the y-axis grows up. As to interoperability of Mac code with iOS code, my experience is that there isn't any (Mac has NSRect, iOS has CGRect, etc.) so the problem doesn't arise - you're going to have two separate code bases in any case. m. -- matt neuburg, phd = m...@tidbits.com, <http://www.tidbits.com/matt/> A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.apeth.net/matt/default.html#applescriptthings _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com