Fwd: CAAnimation working with float, but not with int?

  • Hi Kevin,

    Short answer is interpolating between 1 and 2 with an int wont work.
    There is nothing between 1 and 2 with an int. The CA machinery that
    does the animation will only interpolate (and thus animate) types that
    it knows how to interpolate. Conceptually it could work if you were to
    scale the range up to say 1000 to 2000 and then set the from and to
    values accordingly but AFAIK the CA machinery will still refuse to do
    the interpolation.

    HTH,

    -bd-
    http://bill.dudney.net/roller/objc
    >
    > On Jan 15, 2008, at 11:24 AM, Kevin Barnes wrote:
    >
    >> I'm creating a view and animating an instance variable of that
    >> view. If the instance variable is a float, everything works
    >> perfectly, but if I change the float to an int, the animation
    >> doesn't happen. It appears that the "animationWithKeyPath" function
    >> doesn't even get called if my ivar is an int.
    >> Can anyone tell me why my code doesn't work?
    >>
    >>
    >> Class cls = objc_allocateClassPair([NSView class],
    >> "AnimatedView", 0);
    >> class_addIvar(cls, "animValue", sizeof(int), log2(sizeof(int)),
    >> "i");
    >> Method setterImpl = class_getClassMethod([MyView class],
    >> @selector(setAnimValue:));
    >> class_addMethod(cls, @selector(setAnimValue:),
    >> method_getImplementation(setterImpl), "v@:i");
    >> objc_registerClassPair(cls);
    >>
    >> NSView *av = class_createInstance(cls, 0);
    >> [av init];
    >> CABasicAnimation *anim = [CABasicAnimation
    >> animationWithKeyPath:@"animValue"];
    >> [anim setFromValue:[NSNumber numberWithInt:0]];
    >> NSDictionary *dic = [NSDictionary dictionaryWithObject:anim
    >> forKey:@"animValue"];
    >> [av setAnimations:dic];
    >> [self addSubview:av];
    >>
    >> objc_msgSend([av animator], @selector(setAnimValue:), (int)100);
    >>
    >>
    >> Implementation of setAnimValue:
    >>
    >> +(void)setAnimValue:(int) val {
    >> printf("setAnimValue val=%d\n", val);
    >> }
    >
previous month january 2008 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