Bug 33566 - CAShapeLayer.SetValueForKeyPath does not adhere to animation properties
Summary: CAShapeLayer.SetValueForKeyPath does not adhere to animation properties
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-09-02 09:53 UTC by Matthew Leibowitz
Modified: 2015-09-03 10:14 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

The sample that demonstrates the animation (1.87 MB, application/zip)
2015-09-02 10:24 UTC, Matthew Leibowitz
The original swift code (48 bytes, text/plain)
2015-09-02 10:42 UTC, Matthew Leibowitz

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Matthew Leibowitz 2015-09-02 09:53:53 UTC
I am animating the stroke start and stroke end properties on a CAShapeLayer, but although the stroke animates, the animation does not adhere to the duration and timing function;

    var strokeStart = CABasicAnimation.FromKeyPath("strokeStart");
    strokeStart.To = NSNumber.FromDouble(checkStrokeStart);
    strokeStart.Duration = 0.5;
    strokeStart.TimingFunction = timingFunc;
    shape.AddAnimation (strokeStart, strokeStart.KeyPath);
    shape.SetValueForKeyPath (strokeStart.To, (NSString)strokeStart.KeyPath);

I am porting this library: https://github.com/entotsu/TKAnimatedCheckButton/blob/master/TKAnimatedCheckButton/Classes/TKAnimatedCheckButton.swift 

Some observations:
 * If I don't AddAnimation, then the stroke still animates.
 * If I don't SetValueForKeyPath, then the stroke animates correctly, 
   but as expected, resets after the animation completes
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-09-02 09:59:33 UTC
Can you attach a complete test project we can try out (if you have an equivalent ObjC/Swift sample as well, that would be nice too)?
Comment 2 Matthew Leibowitz 2015-09-02 10:24:52 UTC
Created attachment 12714 [details]
The sample that demonstrates the animation
Comment 3 Matthew Leibowitz 2015-09-02 10:42:26 UTC
Created attachment 12716 [details]
The original swift code
Comment 4 Matthew Leibowitz 2015-09-02 10:55:10 UTC
The swift code is at https://github.com/entotsu/TKAnimatedCheckButton
Comment 5 Matthew Leibowitz 2015-09-03 10:14:46 UTC
This is not a bug, but rather an error of porting swift to C#.

The swift code was:

    layer.actions = [
        "strokeStart": NSNull(),
        "strokeEnd": NSNull(),
        "transform": NSNull()

When I translated to C#, I did:

    layer.Actions = NSDictionary.FromObjectsAndKeys(
        new[] { "strokeStart", "strokeEnd", "transform" },
        new[] { NSNull.Null, NSNull.Null, NSNull.Null });

But, as the method is named, the objects come before the keys:

    layer.Actions = NSDictionary.FromObjectsAndKeys(
        new[] { NSNull.Null, NSNull.Null, NSNull.Null },
        new[] { "strokeStart", "strokeEnd", "transform" });

I should have expected that I made the mistake, and not the development gods on the iOS team :)