Unable to animate gradient layer for shimmer in Xamarin.iOS

sivarlsivarl INMember ✭✭
    CAGradientLayer gradientLayer = new CAGradientLayer();
    gradientLayer.Colors = new CGColor[] { UIColor.Black.CGColor, UIColor.White.ColorWithAlpha(0.1F).CGColor, UIColor.Black.CGColor };
    gradientLayer.StartPoint = new CGPoint(0, 0.5);
    gradientLayer.EndPoint = new CGPoint(1.0, 0.525);
    gradientLayer.Locations = new NSNumber[] { 0.4, 0.5, 0.6 };
    gradientLayer.Frame = new CGRect(- viewEfff.Frame.Width, 0, 3 * viewEfff.Frame.Width, viewEfff.Frame.Height);

    shimmerView.Layer.Mask = gradientLayer;

    CABasicAnimation anmtn = new CABasicAnimation();
    anmtn.KeyPath = "TransGrad";
    anmtn.From = NSArray.FromObjects(new NSNumber[] { 0.0, 0.1, 0.2 });
    anmtn.From = NSArray.FromObjects(new NSNumber[] { 0.8, 0.9, 1.0 });
    anmtn.Duration = 2;
    anmtn.RepeatCount = 1000;
    gradientLayer.AddAnimation(animation, "loc");

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Correct the animation's key path:

    CABasicAnimation anmtn = new CABasicAnimation();
    anmtn.KeyPath = "locations";
    anmtn.From = NSArray.FromObjects(new NSNumber[] { 0.0, 0.1, 0.2 });
    anmtn.From = NSArray.FromObjects(new NSNumber[] { 0.8, 0.9, 1.0 });
    anmtn.Duration = 2;
    anmtn.RepeatCount = 1000;
    gradientLayer.AddAnimation(anmtn, "loc");
    
Sign In or Register to comment.