Accessing CALayer properties

  • Hi,

    I'm testing the new CoreAnimation framework but I can't access or even
    set the properties of the CALayer object.

    The code I'm using is this:

    CGPoint pt = layer.position;

    Instead of this working, I get the following error:  request for
    member 'position' in something not a structure or union.

    Do I need to tell Xcode that I'm using Objective C 2.0 or something?

    PS: the project I'm doing started as a screensaver, but then I added
    an Application target and added the nib and main.m file. Not sure if
    that could cause this problem.

    Thanks in advance,

    Jesus
    __________________
    Jesus De Meyer
    www.edot-studios.com
    jesus.edot-studios.com
    "creativity in mind"
  • On 28 Oct 2007, at 15:53, Jesus De Meyer wrote:

    > I'm testing the new CoreAnimation framework but I can't access or
    > even set the properties of the CALayer object.
    >
    > The code I'm using is this:
    >
    > CGPoint pt = layer.position;
    >
    > Instead of this working, I get the following error:  request for
    > member 'position' in something not a structure or union.

    How have you declared the layer variable? If you declared it as a
    CALayer then it should work. If you declared it as type id then you
    will get this complaint (don't ask me why, but the compiler doesn't
    like property access on variables of type id). Changing the code to
    message sending rather then property access should get rid of the
    complaint at any rate:

    CGPoint pt = [layer position];

    or you can use a cast with the property access notation:

    CGPoint pt = ((CALayer *)layer).position;

    -António

    -----------------------------------------
    Accepting others as they are
    brings a wonderful freedom
    to your own mind.

    --The Peace Formula
    -----------------------------------------
  • My guess is that you're not doing an

    #import <QuartzCore/QuartzCore.h>

    at the top of your file.

    Also, you can access and set all of the properties using the standard
    Cocoa access functions.  I.E.

    CGPoint pt = [layer position];

    ... does the same thing as

    CGPoint pt = layer.position;

    Regards,

    -Tim

    On Oct 28, 2007, at 7:53 AM, Jesus De Meyer wrote:

    > Hi,
    >
    > I'm testing the new CoreAnimation framework but I can't access or
    > even set the properties of the CALayer object.
    >
    > The code I'm using is this:
    >
    > CGPoint pt = layer.position;
    >
    > Instead of this working, I get the following error:  request for
    > member 'position' in something not a structure or union.
    >
    > Do I need to tell Xcode that I'm using Objective C 2.0 or something?
    >
    > PS: the project I'm doing started as a screensaver, but then I added
    > an Application target and added the nib and main.m file. Not sure if
    > that could cause this problem.
    >
    > Thanks in advance,
    >
    > Jesus
    > __________________
    > Jesus De Meyer
    > www.edot-studios.com
    > jesus.edot-studios.com
    > "creativity in mind"
  • > My guess is that you're not doing an
    >
    > #import <QuartzCore/QuartzCore.h>
    >
    > at the top of your file.
    >

    Yeah, that was the issue, so stupid of my part. Thanks

    Now that I have that out of the way. To draw an image to the layer, do
    I just need to create a CGImageRef (either from a CGImageSourceRef)
    and then add that image to the layer's contents property?

    Because I did that and the image didn't draw.

    BTW, I'm drawing to a CustomView and I've set the CA properties in IB
    (wantsLayer and stuff)

    Regards,

    Jesus
    __________________
    Jesus De Meyer
    www.edot-studios.com
    jesus.edot-studios.com
    "creativity in mind"
  • On Oct 28, 2007, at 1:19 PM, Jesus De Meyer wrote:

    > Now that I have that out of the way. To draw an image to the layer,
    > do I just need to create a CGImageRef (either from a
    > CGImageSourceRef) and then add that image to the layer's contents
    > property?

    Well, you could look at the doc...

    >
    >
    > Because I did that and the image didn't draw.
    >

    I'm guessing it's because of either how you're setting up the view, or
    that the view is still being drawn.

    > BTW, I'm drawing to a CustomView and I've set the CA properties in
    > IB (wantsLayer and stuff)

    You're setting up the View to create the layer for your.

    There are two methods of integrating CA and Views.

    Layer-hosting views are views where you

    - create a new layer instance,
    - set it as the layer of the view
    - pass YES to the view method setWantsLayer:

    In this case you are responsible for providing the layer content,
    either by setting the contents property, or by implementing one of the
    layer delegate methods.

    Layer-backed views are views where you

    - create the view
    - pass YES to setWantsLayer:
    - the view automatically creates the layer for you

    This is essentially what IB does.

    Layer-backed views should use the normal view drawing methods.
    Typically you should leave the layer alone.

    So you need to create the view, but not set wants layer in IB, do it
    when the nib is loaded.  also, I'm guessing in this case that the
    existing screensaver might implement the drawRect: method, and so it
    is wiping the content.

    The other day I posted a quick example here that uses CATransitions.
    it loads and displays an image using layers, and should be easy to
    pull apart to get that info.
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today