Re: More CALayer Questions
On Jul 8, 2008, at 2:54 AM, Scott Anguish wrote: I've got a longer answer coming... but There are two ways to interact with layers. - making a view layer-backed (that is, the view and its subviews will use CALayers as a caching mechanism) - using a view to host layers (inserting your custom layers into the layer hierarchy with the view's layer as the root layer) in the first case, you should ignore the layers and not interact with them in the second case you should ignore the view, with the exception of resizing, and do all the layer manipulation yourself. In the second case, would the view handle all interaction, or do the layers get those events as well? ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
On 19-Jul-08, at 5:41 PM, Steven W Riggins wrote: On Jul 8, 2008, at 2:54 AM, Scott Anguish wrote: I've got a longer answer coming... but There are two ways to interact with layers. - making a view layer-backed (that is, the view and its subviews will use CALayers as a caching mechanism) - using a view to host layers (inserting your custom layers into the layer hierarchy with the view's layer as the root layer) in the first case, you should ignore the layers and not interact with them in the second case you should ignore the view, with the exception of resizing, and do all the layer manipulation yourself. In the second case, would the view handle all interaction, or do the layers get those events as well? The view that hosts the layers handles the events. CALayer is lightweight and doesn't take part in the responder chain, or handle events. Now, the hosting view that receives the events can certainly pass them to a layer for handling, but all that is up to the developer to provide support for. The Core Animation Programing Guide chapter Example: Core Animation Menu Application shows how to handle up and down responder events.. that's basically how you'd do it. http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Headstart.html#/ /apple_ref/doc/uid/TP40006131 ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
I've got a longer answer coming... but There are two ways to interact with layers. - making a view layer-backed (that is, the view and its subviews will use CALayers as a caching mechanism) - using a view to host layers (inserting your custom layers into the layer hierarchy with the view's layer as the root layer) in the first case, you should ignore the layers and not interact with them in the second case you should ignore the view, with the exception of resizing, and do all the layer manipulation yourself. Also, consider this. For the second case you should be making the layer yourself and setting it before you enable wantsLayer:. You've created the layer directly. The layer has no knowledge of the coordinate space and flipped-ness of the view it is in, and you didn't provide it. On Jul 7, 2008, at 11:13 PM, Gordon Apple wrote: You may be right that I shouldn't muck with the view's layer, but should add my own base-layer, especially since it seems to be a mystery how the view's layer responds to changes in the view. ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
It's hard to tell, but if you're using a view that you expect to both draw its own content, and that you expect to manipulate and interact directly with the layer (i.e. adding sublayers) you'll have issues. From the hybrid app docs in Animation Overview You can use a combination of layer-backed views, non-layer-backed views, and layer-hosting views in a single user interface with two caveats: • All the subviews of layer-backed views are automatically layer backed. To improve performance, you should avoid making views descendants of layer-backed views if they don’t require animation or cached drawing. • You must host your custom Core Animation layers in a single layer- hosting view rather than inserting them into a layer hierarchy managed by a layer-backed view. If you're doing the second case, none of that view information aside from the frame is at all relevant. The view simply acts as a container. The 'root' layer (that is the layer that is hosted by the view) will always resize so that it fills the entire view. But because frame and bounds in layers behave differently than views (the relationship is much simpler than the scaling that happens in views) the content of the layer won't scale as a result of the frame changing. You shouldn't modify the bounds of a view that is layer-hosting... in fact, it's easiest to simply remember that the root layer resizes to fit the view size, and aside from that how the coordinate system relates is immaterial. If you're adding sublayers to that layer, then you can use springs and struts to resize those layers (to actually scale the displayed content of a layer you'll need to either set the contentsGravity as appropriate (see Positioning Content Within a Layer), or if you're providing the content via the a delegate or subclassing and implementing one of the drawing routines, set the needsDisplayOnBoundsChange method to YES so you can redraw the content when the bound changes.. An update to the view chapter that includes the layer-backing information is forthcoming. But to be honest, it wouldn't have covered most of the questions you're having with coordinate system relationships because if you're layer-backed, you should be ignoring the layer completely. If you're layer hosting, you should only consider the layer itself as being important (aside from the fact that it automatically resizes to fit the view). On Jul 7, 2008, at 3:42 PM, Gordon Apple wrote: What I'm trying to do is conceptually very simple, I just want to scale the view and have its layer position and scale the same, so that drawing into the scaled view comes out the same whether layer-backed or not. Then, once that works, I will try stacking individual sub-layers again. ___ 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 [EMAIL PROTECTED]
More CALayer Questions
I'm suffering from extreme frustration with CALayers. I obviously don't understand the documentation available and there is a lot that is not documented, especially since the Views guide has not been updated to include CALayers. Also, as others have observed, the flipped paremeter in [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES] simply does not work. I have a view with inverted coordinates. I have been able to use a stack of layers to draw when the view is unmodified. However, when I scale the view by any means (usually by changing the frame and resetting to the original bounds), it works without layers, but when using layers I cannot get the layers to track and can't seem to force them into the right scale and position. I've simplified it to just use only the view's layer and still can't get it to work properly. One source of confusion is the anchorPoint/Position relation. Reference says The position is relative to anchorPoint. Huh? What anchorPoint? -- the layer in question, or its superLayer? And what does this mean for the view's layer in terms of the view's coordinates? Another one is frame. Specifies receiver¹s frame rectangle in the super-layer¹s coordinate space. So ok, how does the view's layer frame relate to the view's frame? Both of these questions can likely be answered by the question: How do the view's layer coordinates relate to the view's coordinates? Also, do springs and struts have any meaning between view and layer? The questions are going to get worse when I start trying to change the view's bounds size (drawing canvas size), but let's handle one issue at a time and stick with scaling for now. Apparently, the view's layer corresponds to the view itself when created, with the possible exception of coordinate inversion. I can flip by transforming the context when drawing, but I would rather transform the layer, because the latter is also involved when changing scaling. However, this gets involved with the entire anchorPoint/position question because the transform is not around thelayer's bounds origin, but around the anchorPoint. What I'm trying to do is conceptually very simple, I just want to scale the view and have its layer position and scale the same, so that drawing into the scaled view comes out the same whether layer-backed or not. Then, once that works, I will try stacking individual sub-layers again. Any insights would be appreciated. ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
On 7 Jul '08, at 12:42 PM, Gordon Apple wrote: One source of confusion is the anchorPoint/Position relation. Reference says The position is relative to anchorPoint. Huh? What anchorPoint? -- the layer in question, or its superLayer? And what does this mean for the view's layer in terms of the view's coordinates? When you set the position property of a layer, the point you specify becomes the location (in the superlayer's coords) of the layer's anchorPoint. The anchorPoint is specified in unit coordinates that range from 0 at one side to 1 at the other, so it's independent of scale. So if the layer's anchorPoint is (0.5,0.5), as it is by default, then if you set its position to (100,100), the center point of the layer will be at (100,100). But if the anchorPoint were (0,0), then the top left point of the layer would be at (100,100) ... assuming non-flipped coords. Another one is frame. Specifies receiver’s frame rectangle in the super-layer’s coordinate space. So ok, how does the view's layer frame relate to the view's frame? I am not sure; I don't work with layers directly embedded in views much. (I usually just have one big view and work with layers inside it.) My expectation would be that the layer's frame would be the same as the view's bounds. —Jens___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
OK, a little update. Through watching a number of parameters, a lot of experimentation, and probably blind a** luck, I've managed to get rescaling to sort of work. However, to do editing of objects (e.g., dragging them around), I had to call removeAllAnimations. When I change the scale, the scale does change, but the layer does not change to the correct position until I resize the window -- then it snaps into correct position. Resizing the window results in the drawing disappearing and reappearing, mostly reappearing when downsizing. It also disappears when scrolled, until the window is resized. I assume this has something to do with re-caching the layer. How do I fix that? I need to get this working right before I go back to stacking layers. BTW, I've preordered (July 17) the upcoming book on animation, but I have no idea whether or not it will have anything useful for these CALayer issues. I'm suffering from extreme frustration with CALayers. I obviously don't understand the documentation available and there is a lot that is not documented, especially since the Views guide has not been updated to include CALayers. Also, as others have observed, the flipped paremeter in [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES] simply does not work. ... ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
See my comments embedded below... On Jul 7, 2008, at 3:42 PM, Gordon Apple wrote: I'm suffering from extreme frustration with CALayers. I obviously don't understand the documentation available and there is a lot that is not documented, especially since the Views guide has not been updated to include CALayers. Also, as others have observed, the flipped paremeter in [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES] simply does not work. A layer's context exist without regards to the current drawing context. This makes sense because layer do not necessarily have to be rendered anywhere. Why should they care about the graphic context? If you care about the context when you are drawing, then query the context being passed to your drawing method or delegate method. NSGraphicsContext's -isFlipped method may become your new best friend . ;^} I have a view with inverted coordinates. I have been able to use a stack of layers to draw when the view is unmodified. However, when I scale the view by any means (usually by changing the frame and resetting to the original bounds), it works without layers, but when using layers I cannot get the layers to track and can't seem to force them into the right scale and position. I've simplified it to just use only the view's layer and still can't get it to work properly. What exactly are you doing to scale your views? layers? When scaling layers within a non-scrolling view, I have used the following method: [targetLayer setValue: [NSNumber numverWithFloat: newScaleValue] forKeyPath: @scale]; Usually, I place a statement like this in an action method that is targetted by a slider and it produces no-brainer results When I needed to scale a layer hosted by a view that was enclosed in a NSScrollview, i used the following method: clipView = [targetScrollView contentView]; ` newBoundsSize = NSMakeSize( NSWidth( [clipView frame] ) / newScaleValue, NSHeight( [clipView frame]) / newScaleValue); [clipView setBoundsSize: newBoundsSize]; This works for the most part. The scaling is sluggish and sometimes the view doesn't redraw properly until a scroller is movedc. Have you tried both of these methods? Other methods? One source of confusion is the anchorPoint/Position relation. Reference says The position is relative to anchorPoint. Huh? What anchorPoint? -- the layer in question, or its superLayer? Think of the anchor point as the place where you stick a pin into the layer when positioning it. An anchorpoint of (0.0, 0.0) puts the pin in the lower left corner. An anchorPoint of (0.5, 0.5) puts the pin in the center. And an achorPoint of (1.0, 1.0) places the pin in the upper right corner. Your layer's position will be aligned based on where the pin is stuck. And what does this mean for the view's layer in terms of the view's coordinates? Important: There is no (real) implicit relationship between a view's coordinate system and any of the hosted layer's coordinate system... or at least not one that I have been able to find a reference to. From what I have observed, the view's layer ( i.e., the layer property) seems to operate as if the bounds of the enclosing view defines its geometry. Another one is frame. Specifies receiver’s frame rectangle in the super-layer’s coordinate space. So ok, how does the view's layer frame relate to the view's frame? Both of these questions can likely be answered by the question: How do the view's layer coordinates relate to the view's coordinates? See previous Important notice. For any arbitrary layer that is hosted within a view, there is no actual relationship between the view's frame and the layer's frame. Remember, the frame of a layer is computed dynamically given an anchorPoint, position, bounds and transform matrix. The transform matrix is very important in this equation. Also Important: Note that if you want to convert from a layer's coordinate system to the view coordinate system, there is really no out-of-the-box way to do this. Somewhere in the archives is a discussion of this. If you need to know this relationship (for hit testing, for example) then you'll have to roll your own... or rethink how you are doing this (I had to follow this route, but ultimately it made my code simpler) Also, do springs and struts have any meaning between view and layer? I think not. Layers have no clue as to what a view is. You can't ask a layer what view is currently hosting it. Moreover, a layer can exist without being in a view all together. If you want to manage the springs and struts of you layers, then you need to make friend with CAConstraint. Constraints give you mare flexibility (my opinion) to manage how your layers are laid out in regards to one another The questions are going to get worse when I start trying to change the view's
Re: More CALayer Questions
Hi Gordon, I'm not sure what you really want to do is -removeAllAnimations. I suspect that you probably want to temporarily disable animation within the scope of a CATransaction. Take a look at the code found here: http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Transactions.html#//apple_ref/doc/uid/TP40006096-SW9 later, douglas On Jul 7, 2008, at 6:05 PM, Gordon Apple wrote: OK, a little update. Through watching a number of parameters, a lot of experimentation, and probably blind a** luck, I've managed to get rescaling to sort of work. However, to do editing of objects (e.g., dragging them around), I had to call removeAllAnimations. When I change the scale, the scale does change, but the layer does not change to the correct position until I resize the window -- then it snaps into correct position. Resizing the window results in the drawing disappearing and reappearing, mostly reappearing when downsizing. It also disappears when scrolled, until the window is resized. I assume this has something to do with re-caching the layer. How do I fix that? I need to get this working right before I go back to stacking layers. BTW, I've preordered (July 17) the upcoming book on animation, but I have no idea whether or not it will have anything useful for these CALayer issues. I'm suffering from extreme frustration with CALayers. I obviously don't understand the documentation available and there is a lot that is not documented, especially since the Views guide has not been updated to include CALayers. Also, as others have observed, the flipped paremeter in [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES] simply does not work. ... ___ 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/douglas_welton%40earthlink.net This email sent to [EMAIL PROTECTED] ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
Hi Gordon, 'the upcomming book on animation'? If by that you mean the Core Animation book from Pragmatic Programmers you can get the PDF now from http://www.pragprog.com/titles/bdcora and then the paper when it ships. You get a really good discount on it if you buy both. Not sure where the July 17 date comes from (amazon.com?) but its likely off by at least 2 weeks and probably a bit more like 4. Now on to the real question... Basically what you are doing is confusing the tar out of the layer living in your view by messing with any of its properties. If you do something like this; myView.wantsLayer = YES; And then do something like this; myView.layer.position = myPoint; you are asking for trouble. You should instead do something like this; myView.layer = [CALayer layer]; myView.wantsLayer = YES: layerToMove = [CALayer layer]; [myView.layer addSublayer:layerToMove] then you can layerToMove.position = somePoint; To your hearts desire and everything should be lovely :) Then if you want to do 'struts and springs' type stuff with layerToMove you can use a layoutManager to do all sorts of cool and exciting stuff. Good luck! -bd- http://bill.dudney.net/roller/objc On Jul 7, 2008, at 4:05 PM, Gordon Apple wrote: OK, a little update. Through watching a number of parameters, a lot of experimentation, and probably blind a** luck, I've managed to get rescaling to sort of work. However, to do editing of objects (e.g., dragging them around), I had to call removeAllAnimations. When I change the scale, the scale does change, but the layer does not change to the correct position until I resize the window -- then it snaps into correct position. Resizing the window results in the drawing disappearing and reappearing, mostly reappearing when downsizing. It also disappears when scrolled, until the window is resized. I assume this has something to do with re-caching the layer. How do I fix that? I need to get this working right before I go back to stacking layers. BTW, I've preordered (July 17) the upcoming book on animation, but I have no idea whether or not it will have anything useful for these CALayer issues. I'm suffering from extreme frustration with CALayers. I obviously don't understand the documentation available and there is a lot that is not documented, especially since the Views guide has not been updated to include CALayers. Also, as others have observed, the flipped paremeter in [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES] simply does not work. ... ___ 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/bdudney%40mac.com This email sent to [EMAIL PROTECTED] ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
Thanks. That's a good suggestion. I just realized that the thing was trying to animate and was interfering with my attempts to manually draw. I saw removeAllAnimations and tried it to solved my immediate problem. I'll see if I can use what you mentioned instead. I'm not currently using CALayers for animation (yes, eventually), but just wanted a layering system that will hopefully let me to stack drawing layers, annotation, etc. along with live video layers and other things. Hi Gordon, I'm not sure what you really want to do is -removeAllAnimations. I suspect that you probably want to temporarily disable animation within the scope of a CATransaction. Take a look at the code found here: http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide /Articles/Transactions.html#//apple_ref/doc/uid/TP40006096-SW9 later, douglas The view is a main presentation view that is (optionally) in a scroll view. I started out using the clipView, a la the Sketch example. Then at someone else's suggestion I switched to scaling my main view instead. Either way works great for a non-layer-backed view. The popup in the scroll bar ranges from 10% to 1600%. Currently, I'm just changing the view's frame and then resetting the bounds to the original size. I also tried scaleUnitSquareToSize. It worked, but produced no different result with CALayers. I will also need to be able to change the bounds when the user changes the presentation dimmensions, e.g., 640 x 480 to/from 1024 x 786. All that worked until I tried CALayers. If I could figure out what changing the scroller size does, maybe I could make it do the same thing to adjust properly when the user changes the scale. What exactly are you doing to scale your views? layers? When scaling layers within a non-scrolling view, I have used the following method: [targetLayer setValue: [NSNumber numverWithFloat: newScaleValue] forKeyPath: @scale]; Usually, I place a statement like this in an action method that is targetted by a slider and it produces no-brainer results When I needed to scale a layer hosted by a view that was enclosed in a NSScrollview, i used the following method: clipView = [targetScrollView contentView]; `newBoundsSize = NSMakeSize( NSWidth( [clipView frame] ) / newScaleValue, NSHeight( [clipView frame]) / newScaleValue); [clipView setBoundsSize: newBoundsSize]; This works for the most part. The scaling is sluggish and sometimes the view doesn't redraw properly until a scroller is movedc. Have you tried both of these methods? Other methods? ___ 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 [EMAIL PROTECTED]
Re: More CALayer Questions
Yup, Amazon, July 15, $23.07 + shipping. BTW, you might want them to update the title because it doesn't mention iPhone. Considering the huge number of iPhone SDKs downloaded, that could be a big draw. I may cancel Amazon and order the PDF package from your site. I had considered adding my own base-layer as you suggested, but that still begs the question since that layer will live in the view's layer as a sublayer amd I still don't know how the view's layer responds to changes in the view's frame/bounds. If the view's layer lives within the view's bounds, then I should only have to deal with the flipped coordinates. I was hoping I could flip and scale using a transform so it would carry through to the sublayer stack I wanted to include for my actual drawing layers. That way, I wouldn't have to mess with the sublayer stack -- they should automatically scale when the base-layer is scaled. You may be right that I shouldn't muck with the view's layer, but should add my own base-layer, especially since it seems to be a mystery how the view's layer responds to changes in the view. Gordon Hi Gordon, 'the upcomming book on animation'? If by that you mean the Core Animation book from Pragmatic Programmers you can get the PDF now from http://www.pragprog.com/titles/bdcora and then the paper when it ships. You get a really good discount on it if you buy both. Not sure where the July 17 date comes from (amazon.com?) but its likely off by at least 2 weeks and probably a bit more like 4. Now on to the real question... Basically what you are doing is confusing the tar out of the layer living in your view by messing with any of its properties. If you do something like this; myView.wantsLayer = YES; And then do something like this; myView.layer.position = myPoint; you are asking for trouble. You should instead do something like this; myView.layer = [CALayer layer]; myView.wantsLayer = YES: layerToMove = [CALayer layer]; [myView.layer addSublayer:layerToMove] then you can layerToMove.position = somePoint; To your hearts desire and everything should be lovely :) Then if you want to do 'struts and springs' type stuff with layerToMove you can use a layoutManager to do all sorts of cool and exciting stuff. Good luck! ___ 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 [EMAIL PROTECTED]