Core animation not animating either explicit or implicit animations

Discussion in 'Mac Programming' started by Chirone, May 18, 2009.

  1. Chirone macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #1
    i have a CALayer with core graphics in it and i typed some code to make it do something (anything) on the click of a button.

    in the awakeFromNib method the layer (called graphicsLayer) is instantiated and made a child of another layer which is given to the NSView

    the graphics layer is given bounds and frame so it shows up, and is given a delegate so i can draw on it with core graphics

    now when the button is clicked this code is called:

    Code:
    	printf("%f %f\n", graphicsLayer.position.x, graphicsLayer.position.y);
    	graphicsLayer.position = CGPointMake(500, 20);
    	printf("%f %f\n", graphicsLayer.position.x, graphicsLayer.position.y);
    
    this is by-the-book code and when it's triggered the layer's position is changed (according to the print statement) but on screen nothing happens...

    am i missing something? i tried putting in
    [graphicsLayer setNeedsDisplay];
    after the changing of the position but no luck.

    also i want to animate the stuff that's inside the layer, the core graphics itself... is that possible with core animation or do i need a timer to animate that stuff?

    perhaps i'm animating the wrong thing? trying to animate opacity didn't work either


    another thing

    when i implement the mouseDown method in the NSView the position animates correctly as it should...
    why doesn't the same code only work for the mouseDown method and not the method hooked up to the button?
     
  2. Chirone thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #2
    nevermind

    i think i've figured out the reason

    it came to me as i tried rebuilding the entire project again..

    i have a custom view which is an instance of a class, and an object in IB which is an instance of that same class and from what i'm guessing the two instances aren't the same
     
  3. Chirone thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #3
    ok, say for example i want to animate the layer's position and make it last for a certain duration... so i figure we use the CABasicAnimation thing...

    but how is that done?

    Code:
    	CABasicAnimation *theAnimation;
    	
    	theAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    	theAnimation.duration = 3.0;
    	theAnimation.repeatCount = 2;
    	theAnimation.autoreverses = YES;
    	theAnimation.fromValue = CGPointCreateDictionaryRepresentation(CGPointMake( 137.5, 94));
    	theAnimation.toValue = CGPointCreateDictionaryRepresentation(CGPointMake( 400, 200));
    	[graphicsLayer addAnimation:theAnimation forKey:@"animatePosition"];
    doesn't work. the compiler gives warnings that passing argument 1 of setFromValue (and setToValue) is an incompatible pointer type.

    and just going
    theAnimation.fromValue = CGPointMake(400, 200);
    doesn't work because CGPoint is not an object.. it's a structure

    assuming you can pass in an NSPoint can someone remind me of what the object is that you use to get the NSPoint is?
    (like for making an object for an int you go [NSNumber numberWithInt:], what's the one for NSPoint? i saw it once before so i know it's out there, but it's nowhere to be found in the documentation anymore...)


    Nevermind, found it. NSValue
     

Share This Page