Пример #1
0
 void RemoveLayers()
 {
     if (replicatorLayer != null)
     {
         replicatorLayer.RemoveAllAnimations();
         replicatorLayer.RemoveFromSuperLayer();
         replicatorLayer = null;
     }
 }
Пример #2
0
        void SetupLayers()
        {
            if (view == null || view.Bounds.Size.IsEmpty)
            {
                return;
            }

            RemoveLayers();

            // replicator layer
            replicatorLayer                = new CAReplicatorLayer();
            replicatorLayer.Frame          = view.Bounds;
            replicatorLayer.InstanceCount  = finCount;
            replicatorLayer.PreservesDepth = false;
            replicatorLayer.InstanceColor  = color.CGColor;
            var angle = (nfloat)(Math.PI * 2.0 / (double)finCount);

            replicatorLayer.InstanceTransform = CATransform3D.MakeRotation(angle, 0, 0, 1);

            if (view.Layer == null)
            {
                view.Layer = new CALayer();
            }

            view.Layer.AddSublayer(replicatorLayer);
            view.WantsLayer = true;

            // instance layer
            var layerHeight   = Math.Min(view.Bounds.Width, view.Bounds.Height) * finSizeMultiplier;
            var layerWidth    = layerHeight * finAspectRatio;
            var midX          = view.Bounds.GetMidX() - layerWidth / 2.0;
            var instanceLayer = new CALayer();

            instanceLayer.Frame           = new CGRect(midX, 0, layerWidth, layerHeight);
            instanceLayer.BackgroundColor = color.CGColor;
            instanceLayer.CornerRadius    = (nfloat)(layerWidth / 2.0);
            instanceLayer.Bounds          = new CGRect(CGPoint.Empty, new CGSize(layerWidth, layerHeight));

            replicatorLayer.AddSublayer(instanceLayer);

            // fade animation
            var fadeAnimation = CABasicAnimation.FromKeyPath("opacity");

            fadeAnimation.From        = NSNumber.FromDouble(1.0);
            fadeAnimation.To          = NSNumber.FromDouble(0);
            fadeAnimation.RepeatCount = float.MaxValue;

            //set layer fade animation
            instanceLayer.Opacity  = 0;
            fadeAnimation.Duration = revolutionDuration;
            instanceLayer.AddAnimation(fadeAnimation, "FadeAnimation");

            replicatorLayer.InstanceDelay = revolutionDuration / (double)finCount;
        }
Пример #3
0
        void SetupLayers()
        {
            if (view == null || view.Bounds.Size.IsEmpty)
            {
                return;
            }

            RemoveLayers();

            var width    = view.Bounds.Width;
            var distance = width / 5.0f / (float)shapeCount;

            // replicator layer
            replicatorLayer                   = new CAReplicatorLayer();
            replicatorLayer.Frame             = new CGRect(0, 0, view.Bounds.Width * 2, view.Bounds.Height);
            replicatorLayer.PreservesDepth    = false;
            replicatorLayer.InstanceCount     = (nint)shapeCount;
            replicatorLayer.InstanceTransform = CATransform3D.MakeTranslation(distance, 0, 0);
            replicatorLayer.InstanceDelay     = -0.06f;
            if (view.Layer == null)
            {
                view.Layer = new CALayer();
            }

            view.Layer.AddSublayer(replicatorLayer);
            view.WantsLayer = true;

            // instance layer
            var dotSize       = view.Bounds.Height;
            var instanceLayer = new CALayer();

            instanceLayer.Frame           = new CGRect(-(shapeCount * distance / 2.0f) - dotSize, 0, dotSize, dotSize);
            instanceLayer.BackgroundColor = shapeColor.CGColor;
            instanceLayer.Bounds          = new CGRect(0, 0, dotSize, dotSize);
            instanceLayer.CornerRadius    = dotSize / 2.0f;
            replicatorLayer.AddSublayer(instanceLayer);

            var runAnimation = CABasicAnimation.FromKeyPath("transform.translation.x");

            runAnimation.From           = NSNumber.FromDouble(-2f * width);
            runAnimation.To             = NSNumber.FromDouble(3f * width);
            runAnimation.Duration       = duration;
            runAnimation.RepeatCount    = float.PositiveInfinity;
            runAnimation.TimingFunction = CAMediaTimingFunction.FromControlPoints(0, 1.0f - easeFactor, 1, easeFactor);

            instanceLayer.AddAnimation(runAnimation, "RunAnimation");
        }
Пример #4
0
        void SetupLayers()
        {
            if (view == null || view.Bounds.Size.IsEmpty)
            {
                return;
            }

            RemoveLayers();

            var shear = new CGAffineTransform(1.0f, 0, shearFactor, 1.0f, 0.0f, 0.0f);

            // replicator layer
            replicatorLayer = new CAReplicatorLayer();
            replicatorLayer.BackgroundColor   = trackColor.CGColor;
            replicatorLayer.Frame             = view.Bounds;
            replicatorLayer.InstanceCount     = (nint)(1 + view.Bounds.Width / hatchSize);
            replicatorLayer.PreservesDepth    = false;
            replicatorLayer.InstanceTransform = CATransform3D.MakeTranslation((nfloat)(hatchSize * 2.0), 0, 0);

            if (view.Layer == null)
            {
                view.Layer = new CALayer();
            }

            view.Layer.AddSublayer(replicatorLayer);
            view.WantsLayer = true;

            // instance layer
            var layerHeight   = view.Bounds.Height;
            var layerWidth    = hatchSize;
            var instanceLayer = new CALayer();

            instanceLayer.Frame           = new CGRect(0, 0, layerWidth, layerHeight);
            instanceLayer.BackgroundColor = hatchColor.CGColor;
            instanceLayer.Bounds          = new CGRect(0, 0, layerWidth, layerHeight);
            instanceLayer.Transform       = CATransform3D.MakeFromAffine(shear);
            replicatorLayer.AddSublayer(instanceLayer);

            var runAnimation = CABasicAnimation.FromKeyPath("transform.translation.x");

            runAnimation.From        = NSNumber.FromDouble(-hatchSize);
            runAnimation.To          = NSNumber.FromDouble(hatchSize);
            runAnimation.Duration    = 0.5;
            runAnimation.RepeatCount = float.PositiveInfinity;
            instanceLayer.AddAnimation(runAnimation, "RunAnimation");
        }