コード例 #1
0
        void UpdateRecordButton(bool isRecording)
        {
            //Corner Radius
            var radiusAnimation = CABasicAnimation.FromKeyPath("cornerRadius");

            radiusAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            radiusAnimation.From           = NSNumber.FromNFloat(recordButton.Layer.CornerRadius);

            //Border Thickness
            var borderAnimation = CABasicAnimation.FromKeyPath("borderWidth");

            borderAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            radiusAnimation.From           = NSNumber.FromNFloat(recordButton.Layer.BorderWidth);

            //Animation Group
            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Animations = new CAAnimation[] { radiusAnimation, borderAnimation };
            animationGroup.Duration   = 0.6;
            animationGroup.FillMode   = CAFillMode.Forwards;

            recordButton.Layer.CornerRadius = isRecording ? 4 : recordButton.Frame.Width / 2;
            recordButton.Layer.BorderWidth  = isRecording ? 2 : 3;

            recordButton.Layer.AddAnimation(animationGroup, "borderChanges");
        }
コード例 #2
0
        void StartAnimation()
        {
            this._pathLayer.RemoveAllAnimations();

            CABasicAnimation pathAnimation = CABasicAnimation.FromKeyPath(@"strokeEnd");

            pathAnimation.Duration = 2f;
            pathAnimation.From     = NSNumber.FromNFloat(0);
            pathAnimation.To       = NSNumber.FromNFloat(1);
            this._pathLayer.AddAnimation(pathAnimation, @"strokeEnd");
            this._cicleLayer.RemoveAllAnimations();

            CABasicAnimation circleAnimation = CABasicAnimation.FromKeyPath(@"strokeEnd");

            circleAnimation.Duration = 2f;
            circleAnimation.From     = NSNumber.FromNFloat(0);
            circleAnimation.To       = NSNumber.FromNFloat(1);
            this._cicleLayer.AddAnimation(circleAnimation, @"strokeEnd");

            this._circleLayerWhite.RemoveAllAnimations();

            CABasicAnimation circleAnimationWhite = CABasicAnimation.FromKeyPath(@"strokeEnd");

            circleAnimationWhite.Duration = 2f;
            circleAnimationWhite.From     = NSNumber.FromNFloat(0);
            circleAnimationWhite.To       = NSNumber.FromNFloat(1);
            this._circleLayerWhite.AddAnimation(circleAnimationWhite, @"strokeEnd");
        }
コード例 #3
0
        public override void UpdateViewConstraints()
        {
            // update is used only when updating the constant value
            growingButton.UpdateConstraints(make =>
            {
                make.Center.EqualTo(View);
                make.Width.EqualTo(NSNumber.FromNFloat(buttonSize.Width)).PriorityLow();
                make.Height.EqualTo(NSNumber.FromNFloat(buttonSize.Height)).PriorityLow();
                make.Width.LessThanOrEqualTo(View);
                make.Height.LessThanOrEqualTo(View);
            });

            // remake is used when changing constraints
            movingButton.RemakeConstraints(make =>
            {
                make.Height.EqualTo(NSNumber.FromNFloat(250));
                make.Width.EqualTo(movingButton.Height()).MultipliedBy(2.0f);

                if (topLeft)
                {
                    make.Left.EqualTo(View.LeftMargin());
                    make.Top.EqualTo(this.TopLayoutGuide());
                }
                else
                {
                    make.Right.EqualTo(View.RightMargin());
                    make.Bottom.EqualTo(this.BottomLayoutGuide());
                }
            });

            base.UpdateViewConstraints();
        }
コード例 #4
0
        /// <summary>
        /// Touchs up animation.
        /// </summary>
        public void TouchUpAnimation()
        {
            foreach (UIImageView Icon in IconArray)
            {
                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () =>
                {
                    Icon.Alpha = 0.0f;
                }
                                     , (finished) =>
                {
                    Icon.Hidden = true;
                });
            }

            var ButtonScaleSmallCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleSmallCABasicAnimation.Duration            = 0.2f;
            ButtonScaleSmallCABasicAnimation.AutoReverses        = false;
            ButtonScaleSmallCABasicAnimation.To                  = NSNumber.FromFloat(1.0f);
            ButtonScaleSmallCABasicAnimation.From                = NSNumber.FromFloat(BigRadius / SmallRadius);
            ButtonScaleSmallCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleSmallCABasicAnimation.RemovedOnCompletion = false;

            SmallButton.Layer.AddAnimation(ButtonScaleSmallCABasicAnimation, @"ButtonScaleSmallCABasicAnimation");


            var BackgroundViewScaleSmallCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            BackgroundViewScaleSmallCABasicAnimation.Duration            = 0.1f;
            BackgroundViewScaleSmallCABasicAnimation.AutoReverses        = false;
            BackgroundViewScaleSmallCABasicAnimation.To                  = NSNumber.FromFloat(1.0f);
            BackgroundViewScaleSmallCABasicAnimation.From                = NSNumber.FromNFloat(this.Frame.Size.Height / SmallRadius);
            BackgroundViewScaleSmallCABasicAnimation.FillMode            = CAFillMode.Forwards;
            BackgroundViewScaleSmallCABasicAnimation.RemovedOnCompletion = false;


            BackgroundView.Layer.AddAnimation(BackgroundViewScaleSmallCABasicAnimation, @"BackgroundViewScaleSmallCABasicAnimation");

            var Rotate = CATransform3D.MakeRotation(0, 0, 1, 0).Concat(CATransform3D.MakeRotation(0, 1, 0, 0));

            if (Parallex)
            {
                SmallButton.Layer.Transform = CATransform3DPerspect(Rotate, new CGPoint(0, 0), BigRadius + ParallexParameter);
            }
            else
            {
                //Do nothing ^_^
            }

            SmallButton.SetImage(IconImage, UIControlState.Normal);

            UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () =>
            {
                SmallButton.ImageView.Alpha = 1.0f;
            }
                                 , (finished) =>
            {
            });
        }
コード例 #5
0
 void UpdateGradientLayer()
 {
     GradientLayer.Frame     = new CGRect(CGPoint.Empty, Bounds.Size);
     GradientLayer.Locations = new [] {
         NSNumber.FromNFloat(MaskPosition.Y / Bounds.Height),
         NSNumber.FromNFloat(MaskPosition.X / Bounds.Height)
     };
 }
コード例 #6
0
        /// <summary>
        /// Shows the complete screen.
        /// </summary>
        /// <param name="message">Message to display</param>
        /// <param name="wasSuccessful">If set to <c>true</c> was process successful.</param>
        public void ShowCompleteScreen(string message, bool wasSuccessful)
        {
            var image = (wasSuccessful) ? UIImage.FromBundle("CallbackSuccess") : UIImage.FromBundle("CallbackWrong");

            CallbackIcon.Image   = image;
            CallbackMessage.Text = message;

            UIView.AnimateNotify(0.3f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackMessage.Alpha = 1.0f; }, (finished) => {});
            UIView.AnimateNotify(0.3f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackIcon.Alpha = 1.0f; }, (finished) => {});

            var ButtonScaleKeepCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleKeepCABasicAnimation.Duration            = 2.0f;
            ButtonScaleKeepCABasicAnimation.AutoReverses        = false;
            ButtonScaleKeepCABasicAnimation.From                = NSNumber.FromNFloat(FullPara);
            ButtonScaleKeepCABasicAnimation.To                  = NSNumber.FromNFloat(FullPara);
            ButtonScaleKeepCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleKeepCABasicAnimation.RemovedOnCompletion = false;
            ButtonScaleKeepCABasicAnimation.BeginTime           = 0.0f;

            var ButtonScaleSmallCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleSmallCABasicAnimation.Duration            = 0.2f;
            ButtonScaleSmallCABasicAnimation.AutoReverses        = false;
            ButtonScaleSmallCABasicAnimation.From                = NSNumber.FromNFloat(FullPara);
            ButtonScaleSmallCABasicAnimation.To                  = NSNumber.FromDouble(SmallPara);
            ButtonScaleSmallCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleSmallCABasicAnimation.RemovedOnCompletion = false;
            ButtonScaleSmallCABasicAnimation.BeginTime           = 2.0f;

            SmallButton.Layer.AddAnimation(ButtonScaleSmallCABasicAnimation, @"ButtonScaleAnimation");

            var animGroup = CAAnimationGroup.CreateAnimation();

            animGroup.Animations          = new CAAnimation[] { ButtonScaleKeepCABasicAnimation, ButtonScaleSmallCABasicAnimation };
            animGroup.Duration            = 2.2f;
            animGroup.RemovedOnCompletion = false;
            animGroup.AutoReverses        = false;
            animGroup.FillMode            = CAFillMode.Forwards;


            CATransaction.Begin();

            CATransaction.CompletionBlock = () => {
                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackIcon.Alpha = 0.0f; }, (finished) => {});
                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackMessage.Alpha = 0.0f; }, (finished) => {});

                SmallButton.SetImage(IconImage, UIControlState.Normal);

                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { SmallButton.ImageView.Alpha = 1.0f; }, (finished) => {});
            };

            SmallButton.Layer.AddAnimation(animGroup, @"ButtonScaleAnimation");
            CATransaction.Commit();
        }
コード例 #7
0
        void BurstTapCircle()
        {
            nfloat tapCircleFinalDiameter = CalculateTapCircleFinalDiameter();

            tapCircleFinalDiameter += TapCircleBurstAmount;

            var endingRectSizerView = new UIView(new CGRect(0, 0, tapCircleFinalDiameter, tapCircleFinalDiameter));

            endingRectSizerView.Center = RippleFromTapLocation ? TapPoint : new CGPoint(Bounds.GetMidX(), Bounds.GetMidY());

            UIBezierPath endingCirclePath = UIBezierPath.FromRoundedRect(endingRectSizerView.Frame, tapCircleFinalDiameter / 2f);

            CAShapeLayer tapCircle = (RippleAnimationQueue.Count > 0) ? RippleAnimationQueue.GetItem <CAShapeLayer>(0) : null;

            if (tapCircle != null)
            {
                if (RippleAnimationQueue.Count > 0)
                {
                    RippleAnimationQueue.RemoveObject(0);
                }
                DeathRowForCircleLayers.AddObjects(new NSObject[] { tapCircle });

                CGPath startingPath    = tapCircle.Path;
                nfloat startingOpacity = tapCircle.Opacity;

                if (tapCircle.AnimationKeys != null && tapCircle.AnimationKeys.Length > 0)
                {
                    startingPath = tapCircle.Path;
                    if (tapCircle.PresentationLayer != null)
                    {
                        startingOpacity = tapCircle.PresentationLayer.Opacity;
                    }
                }

                CABasicAnimation tapCircleGrowthAnimation = CABasicAnimation.FromKeyPath("path");
                tapCircleGrowthAnimation.Duration       = TouchUpAnimationDuration;
                tapCircleGrowthAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                tapCircleGrowthAnimation.SetFrom(startingPath);
                tapCircleGrowthAnimation.SetTo(endingCirclePath.CGPath);
                tapCircleGrowthAnimation.FillMode            = CAFillMode.Forwards;
                tapCircleGrowthAnimation.RemovedOnCompletion = false;

                CABasicAnimation fadeOut = CABasicAnimation.FromKeyPath("opacity");
                fadeOut.SetValueForKey(new NSString("fadeCircleOut"), new NSString("id"));
                fadeOut.SetFrom(NSNumber.FromNFloat(startingOpacity));
                fadeOut.SetTo(NSNumber.FromNFloat(0f));
                fadeOut.Duration            = TouchUpAnimationDuration;
                fadeOut.FillMode            = CAFillMode.Forwards;
                fadeOut.RemovedOnCompletion = false;

                tapCircle.AddAnimation(tapCircleGrowthAnimation, "animatePath");
                tapCircle.AddAnimation(fadeOut, "opacityAnimation");
            }
        }
コード例 #8
0
        private CAAnimation createAnimation()
        {
            var animation = CABasicAnimation.FromKeyPath("transform.rotation.z");

            animation.Duration       = animationDuration;
            animation.TimingFunction = Curves.Linear.ToMediaTimingFunction();
            animation.Cumulative     = true;
            animation.From           = NSNumber.FromNFloat(0);
            animation.To             = NSNumber.FromNFloat((nfloat)FullCircle);
            animation.RepeatCount    = float.PositiveInfinity;
            return(animation);
        }
コード例 #9
0
        void configureConstraints()
        {
            var views = new NSDictionary(
                new NSString(@"bodyLabel"), BodyLabel
                );

            var metrics = new NSDictionary(
                new NSString(@"tumbSize"), NSNumber.FromNFloat(30),
                new NSString(@"right"), NSNumber.FromNFloat(10)
                );

            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(@"H:|-tumbSize-[bodyLabel(>=0)]-right-|", 0, metrics, views));
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(@"V:|[bodyLabel]|", 0, metrics, views));
        }
コード例 #10
0
        private UIAlertController CreateLoadingPopup(string title)
        {
            var alertController = UIAlertController.Create("Creating account", "", UIAlertControllerStyle.Alert);
            var loader          = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray);

            loader.StartAnimating();

            alertController.Add(loader); loader.MakeConstraints(make =>
            {
                make.Left.EqualTo(NSNumber.FromNFloat(30));
                make.CenterY.EqualTo(alertController);
            });

            return(alertController);
        }
コード例 #11
0
        public static CABasicAnimation TranslateZ(nfloat translation, double?duration = null)
        {
            var animation = CABasicAnimation.FromKeyPath("transform.translation.z");

            animation.To = NSNumber.FromNFloat(translation);

            animation.FillMode            = Convert.MaterialAnimationFillModeToValue(MaterialAnimationFillMode.Forwards);
            animation.RemovedOnCompletion = false;
            animation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            if (duration != null)
            {
                animation.Duration = duration.Value;
            }
            return(animation);
        }
コード例 #12
0
        // takes an array of NSNumbers in the range self.minimumValue - self.maximumValue
        // returns an array of NSNumbers in the range 0.0 - 1.0
        private NSNumber[] KeyTimesFromSliderPositions(NSNumber[] positions)
        {
            if (positions == null)
            {
                return(null);
            }

            Array.Sort(positions);

            var temp = new List <NSNumber>();

            foreach (var num in positions)
            {
                temp.Add(NSNumber.FromNFloat((num.FloatValue - MinValue) / valueRange));
            }
            return(temp.ToArray());
        }
コード例 #13
0
        void LiftButton()
        {
            if (IsRaised)
            {
                nfloat startRadius  = LoweredShadowRadius;
                nfloat startOpacity = LoweredShadowOpacity;
                CGPath startPath    = UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath;

                if (Layer.AnimationKeys != null && Layer.AnimationKeys.Length > 0)
                {
                    startRadius  = Layer.PresentationLayer.ShadowRadius;
                    startOpacity = Layer.PresentationLayer.ShadowOpacity;
                    startPath    = Layer.PresentationLayer.ShadowPath;
                }

                CABasicAnimation increaseRadius = CABasicAnimation.FromKeyPath("shadowRadius");
                increaseRadius.From                = NSNumber.FromNFloat(startRadius);
                increaseRadius.To                  = NSNumber.FromNFloat(LiftedShadowRadius);
                increaseRadius.Duration            = TouchDownAnimationDuration;
                increaseRadius.FillMode            = CAFillMode.Forwards;
                increaseRadius.RemovedOnCompletion = true;
                Layer.ShadowRadius                 = LiftedShadowRadius;

                CABasicAnimation shadowOpacityAnimation = CABasicAnimation.FromKeyPath("shadowOpacity");
                shadowOpacityAnimation.Duration            = TouchDownAnimationDuration;
                shadowOpacityAnimation.From                = NSNumber.FromNFloat(startOpacity);
                shadowOpacityAnimation.To                  = NSNumber.FromNFloat(LiftedShadowOpacity);
                shadowOpacityAnimation.FillMode            = CAFillMode.Backwards;
                shadowOpacityAnimation.RemovedOnCompletion = true;
                Layer.ShadowOpacity = LiftedShadowOpacity;

                CABasicAnimation shadowPathAnimation = CABasicAnimation.FromKeyPath("shadowPath");
                shadowPathAnimation.Duration = TouchDownAnimationDuration;
                shadowPathAnimation.SetFrom(startPath);
                shadowPathAnimation.SetTo(UIBezierPath.FromRoundedRect(UpRect, CornerRadius).CGPath);
                shadowPathAnimation.FillMode            = CAFillMode.Forwards;
                shadowPathAnimation.RemovedOnCompletion = true;
                Layer.ShadowPath = UIBezierPath.FromRoundedRect(UpRect, CornerRadius).CGPath;

                Layer.AddAnimation(increaseRadius, "shadowRadius");
                Layer.AddAnimation(shadowOpacityAnimation, "shadowOpacity");
                Layer.AddAnimation(shadowPathAnimation, "shadow");
            }
        }
コード例 #14
0
        /// <summary>
        /// Touches down animation.
        /// </summary>
        public void TouchDownAnimation()
        {
            UIView.AnimateNotify(0.1f, 0, UIViewAnimationOptions.BeginFromCurrentState, () => {
                SmallButton.ImageView.Alpha = 0.0f;
            }, (finished) => {
                if (finished)
                {
                    SmallButton.SetImage(null, UIControlState.Normal);
                }
            });

            var ButtonScaleBigCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleBigCABasicAnimation.Duration            = 0.1f;
            ButtonScaleBigCABasicAnimation.AutoReverses        = false;
            ButtonScaleBigCABasicAnimation.From                = NSNumber.FromFloat(1.0f);
            ButtonScaleBigCABasicAnimation.To                  = NSNumber.FromFloat(BigRadius / SmallRadius);
            ButtonScaleBigCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleBigCABasicAnimation.RemovedOnCompletion = false;

            SmallButton.Layer.AddAnimation(ButtonScaleBigCABasicAnimation, @"ButtonScaleBigCABasicAnimation");

            var BackgroundViewScaleBigCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            BackgroundViewScaleBigCABasicAnimation.Duration            = 0.1f;
            BackgroundViewScaleBigCABasicAnimation.AutoReverses        = false;
            BackgroundViewScaleBigCABasicAnimation.From                = NSNumber.FromFloat(1.0f);
            BackgroundViewScaleBigCABasicAnimation.To                  = NSNumber.FromNFloat(this.Frame.Size.Height / SmallRadius);
            BackgroundViewScaleBigCABasicAnimation.FillMode            = CAFillMode.Forwards;
            BackgroundViewScaleBigCABasicAnimation.RemovedOnCompletion = false;

            BackgroundView.Layer.AddAnimation(BackgroundViewScaleBigCABasicAnimation, @"BackgroundViewScaleBigCABasicAnimation");

            foreach (UIImageView Icon in IconArray)
            {
                this.Layer.RemoveAllAnimations();
                Icon.Hidden = false;

                UIView.AnimateNotify(0.3f, 0, UIViewAnimationOptions.BeginFromCurrentState, () => {
                    Icon.Alpha = 0.7f;
                }, (finished) => {
                });
            }
        }
コード例 #15
0
ファイル: TapEffect.cs プロジェクト: wys0120/Xamarin.DuGuLib
            private void SetAni(float from, float to, double duration = 0.3)
            {
                this.Layer.RemoveAnimation("radius");
                using (var ani = CABasicAnimation.FromKeyPath("radius"))
                {
                    ani.Duration = duration;
                    ani.From = NSNumber.FromNFloat(from);
                    ani.To = NSNumber.FromFloat(to);
                    //ani.SetTo(NSNumber.FromFloat(to));
                    ani.AutoReverses = false;
                    ani.RepeatCount = 1;
                    //http://www.jianshu.com/p/02c341c748f9
                    ani.RemovedOnCompletion = false;
                    ani.FillMode = CAFillMode.Backwards;

                    ani.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                    this.Layer.AddAnimation(ani, "radius");
                }
            }
コード例 #16
0
ファイル: ViewExtensions.cs プロジェクト: blparr/XWeather
        static CAGradientLayer visibilityMaskWithLocation(this UIView view, nfloat location, bool reverse = false)
        {
            var mask = new CAGradientLayer();

            mask.Frame = view.Bounds;

            if (reverse)
            {
                mask.Colors = new [] { UIColor.FromWhiteAlpha(1, 1).CGColor, UIColor.FromWhiteAlpha(1, 0).CGColor };
            }
            else
            {
                mask.Colors = new [] { UIColor.FromWhiteAlpha(1, 0).CGColor, UIColor.FromWhiteAlpha(1, 1).CGColor };
            }

            mask.Locations = new [] { NSNumber.FromNFloat(location), NSNumber.FromNFloat(location) };

            return(mask);
        }
コード例 #17
0
        public static void ApplyShimmer(UIView viewToApplyShimmer)
        {
            var gradientLayer = new CAGradientLayer
            {
                Colors     = new CGColor[] { UIColor.White.ColorWithAlpha(0f).CGColor, UIColor.White.ColorWithAlpha(1f).CGColor, UIColor.White.ColorWithAlpha(0f).CGColor },
                StartPoint = new CGPoint(0.7, 1.0),
                EndPoint   = new CGPoint(0, 0.8),
                Frame      = viewToApplyShimmer.Bounds
            };

            viewToApplyShimmer.Layer.InsertSublayer(gradientLayer, 0);

            var animation = new CABasicAnimation();

            animation.KeyPath     = "transform.translation.x";
            animation.Duration    = 1;
            animation.From        = NSNumber.FromNFloat(-viewToApplyShimmer.Frame.Size.Width);
            animation.To          = NSNumber.FromNFloat(viewToApplyShimmer.Frame.Size.Width);
            animation.RepeatCount = float.PositiveInfinity;

            gradientLayer.AddAnimation(animation, "");
        }
コード例 #18
0
        void AddChipLayerAtColumnRowColor(int column, int row, UIColor color)
        {
            int count = chipLayers [column].Count(c => c != null);

            if (count < row + 1)
            {
                var newChip = (CAShapeLayer)CAShapeLayer.Create();
                newChip.Path      = chipPath.CGPath;
                newChip.Frame     = chipPath.Bounds;
                newChip.FillColor = color.CGColor;
                newChip.Position  = PositionForChipLayerAtColumnRow(column, row);

                View.Layer.AddSublayer(newChip);
                CABasicAnimation animation = CABasicAnimation.FromKeyPath("position.y");
                animation.From     = NSNumber.FromNFloat(newChip.Frame.Height);
                animation.To       = NSNumber.FromNFloat(newChip.Position.Y);
                animation.Duration = 0.5;

                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
                newChip.AddAnimation(animation, null);
                chipLayers [column] [row] = newChip;
            }
        }
コード例 #19
0
        public AnimationBuilder RotateDegrees(nfloat fromDegrees, nfloat toDegrees, double delaySeconds, double durationSeconds)
        {
            // chip rotation
            var animateRotate = CABasicAnimation.FromKeyPath("transform.rotation.z");

            animateRotate.TimingFunction = this.EasingFunction;
            if (durationSeconds > 0)
            {
                animateRotate.Duration = durationSeconds;
            }
            if (delaySeconds > 0)
            {
                animateRotate.BeginTime = delaySeconds;
            }
            animateRotate.FillMode            = CAFillMode.Forwards;
            animateRotate.RemovedOnCompletion = false;
            animateRotate.From = NSNumber.FromNFloat(fromDegrees.ToRadians());
            animateRotate.To   = NSNumber.FromNFloat(toDegrees.ToRadians());

            this.Animations.Add(animateRotate);
            this.EnsureTotalDuration(delaySeconds, durationSeconds);

            return(this);
        }
コード例 #20
0
        void addIndeterminateAnimation()
        {
            var indeterminate = progressLayer.AnimationForKey(CircularProgressAnimationKeys.indeterminate);

            if (indeterminate == null)
            {
                var animation = CABasicAnimation.FromKeyPath(CircularProgressAnimationKeys.transformRotation);

                animation.By = NSNumber.FromNFloat(ClockwiseProgress ? 2 * NMath.PI : -2 * NMath.PI);

                animation.Duration = IndeterminateDuration;

                animation.RepeatCount = float.MaxValue;

                //animation.RemovedOnCompletion = false;
                animation.RemovedOnCompletion = true;

                progressLayer.Progress = IndeterminateProgress;

                progressLayer.AddAnimation(animation, CircularProgressAnimationKeys.indeterminate);
            }

            progressLayer.Progress = IndeterminateProgress;
        }
コード例 #21
0
        /// <summary>
        /// Touchs up inside animation.
        /// </summary>
        public void TouchUpInsideAnimation()
        {
            this.IsPerformingTouchUpInsideAnimation = true;

            foreach (UIImageView Icon in IconArray)
            {
                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () =>
                {
                    Icon.Alpha = 0.0f;
                }, (finished) =>
                {
                    if (finished)
                    {
                        Icon.Hidden = true;
                    }
                });
            }

            var BackgroundViewScaleSmallCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            BackgroundViewScaleSmallCABasicAnimation.Duration            = 0.1f;
            BackgroundViewScaleSmallCABasicAnimation.AutoReverses        = false;
            BackgroundViewScaleSmallCABasicAnimation.To                  = NSNumber.FromDouble(SmallPara);
            BackgroundViewScaleSmallCABasicAnimation.From                = NSNumber.FromDouble(MidiumPara);
            BackgroundViewScaleSmallCABasicAnimation.FillMode            = CAFillMode.Forwards;
            BackgroundViewScaleSmallCABasicAnimation.RemovedOnCompletion = false;
            BackgroundViewScaleSmallCABasicAnimation.BeginTime           = 0.0f;

            BackgroundView.Layer.AddAnimation(BackgroundViewScaleSmallCABasicAnimation, @"BackgroundViewScaleSmallCABasicAnimation");

            var ButtonScaleFullCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleFullCABasicAnimation.Duration            = 0.2f;
            ButtonScaleFullCABasicAnimation.AutoReverses        = false;
            ButtonScaleFullCABasicAnimation.To                  = NSNumber.FromNFloat(FullPara);
            ButtonScaleFullCABasicAnimation.From                = NSNumber.FromDouble(MidiumPara);
            ButtonScaleFullCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleFullCABasicAnimation.RemovedOnCompletion = false;
            ButtonScaleFullCABasicAnimation.BeginTime           = 0.0f;

            var animGroup = CAAnimationGroup.CreateAnimation();

            animGroup.Animations          = new CAAnimation[] { ButtonScaleFullCABasicAnimation };
            animGroup.Duration            = 0.4f;
            animGroup.RemovedOnCompletion = false;
            animGroup.AutoReverses        = false;
            animGroup.FillMode            = CAFillMode.Forwards;

            CATransaction.Begin();
            CATransaction.CompletionBlock = () => {
                IsPerformingTouchUpInsideAnimation = false;
            };

            SmallButton.Layer.AddAnimation(animGroup, @"ButtonScaleAnimation");
            CATransaction.Commit();


            CATransform3D Rotate = CATransform3D.MakeRotation(0, 0, 1, 0).Concat(CATransform3D.MakeRotation(0, 1, 0, 0));

            if (Parallex)
            {
                SmallButton.Layer.Transform = CATransform3DPerspect(Rotate, new CGPoint(0, 0), BigRadius + ParallexParameter);
            }
            else
            {
                //Do nothing ^_^
            }
        }
コード例 #22
0
        public ActivityArcView(IntPtr ptr)
            : base(ptr)
        {
            _shadowStrokeColor = UIColor.FromRGB(0xe0, 0xe0, 0xe0);
            _arcStrokeColor    = UIColor.Black;

            _arcLayer = new CAShapeLayer()
            {
                StrokeColor = _arcStrokeColor.CGColor
            };
            _shadowLayer = new CAShapeLayer()
            {
                StrokeColor = _shadowStrokeColor.CGColor,
                FillColor   = _arcLayer.FillColor = null,
                StrokeStart = _arcLayer.StrokeStart = 0f,
                LineWidth   = _arcLayer.LineWidth = 4f,
                LineCap     = _arcLayer.LineCap = CAShapeLayer.CapRound,
            };
            _textLayer = new CATextLayer()
            {
                Hidden            = true,
                TextAlignmentMode = CATextLayerAlignmentMode.Center,
                ForegroundColor   = UIColor.DarkTextColor.CGColor
            };
            _textLayer.ContentsScale
                    = _textLayer.RasterizationScale
                    = _shadowLayer.RasterizationScale
                    = _arcLayer.RasterizationScale = UIScreen.MainScreen.Scale;

            Layer.AddSublayer(_shadowLayer);
            Layer.AddSublayer(_arcLayer);
            Layer.AddSublayer(_textLayer);

            SetupRotationAnimation();
            SetupStrokeAnimation();
            SetupColorAnimation();

            var path = CreateArcPath(5f);

            _pathGrowAnimation                     = CABasicAnimation.FromKeyPath("path");
            _pathGrowAnimation.Duration            = 0.5f;
            _pathGrowAnimation.RemovedOnCompletion = false;
            _pathGrowAnimation.FillMode            = CAFillMode.Forwards;
            _pathGrowAnimation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            _pathGrowAnimation.AnimationStopped   += (x, y) =>
            {
                _shadowLayer.Path = _pathGrowAnimation.GetToAs <CGPath>();
                UpdateLayers();
            };

            _pathShrinkAnimation                     = CABasicAnimation.FromKeyPath("path");
            _pathShrinkAnimation.Duration            = 0.5f;
            _pathShrinkAnimation.RemovedOnCompletion = false;
            _pathShrinkAnimation.FillMode            = CAFillMode.Forwards;
            _pathShrinkAnimation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            _pathShrinkAnimation.AnimationStopped   += (x, y) =>
            {
                _shadowLayer.Path = _pathShrinkAnimation.GetToAs <CGPath>();
                UpdateLayers();
            };


            _pathOpacityUpAnimation                     = CABasicAnimation.FromKeyPath("opacity");
            _pathOpacityUpAnimation.From                = NSNumber.FromNFloat(0f);
            _pathOpacityUpAnimation.To                  = NSNumber.FromNFloat(1f);
            _pathOpacityUpAnimation.Duration            = 0.5f;
            _pathOpacityUpAnimation.FillMode            = CAFillMode.Forwards;
            _pathOpacityUpAnimation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            _pathOpacityUpAnimation.RemovedOnCompletion = false;
            _pathOpacityUpAnimation.AnimationStopped   += (x, y) =>
            {
                _shadowLayer.Opacity = _arcLayer.Opacity = _pathOpacityUpAnimation.GetToAs <NSNumber>().FloatValue;
            };

            _pathOpacityDownAnimation                     = CABasicAnimation.FromKeyPath("opacity");
            _pathOpacityDownAnimation.From                = NSNumber.FromNFloat(1f);
            _pathOpacityDownAnimation.To                  = NSNumber.FromNFloat(0f);
            _pathOpacityDownAnimation.Duration            = 0.5f;
            _pathOpacityDownAnimation.FillMode            = CAFillMode.Forwards;
            _pathOpacityDownAnimation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            _pathOpacityDownAnimation.RemovedOnCompletion = false;
            _pathOpacityDownAnimation.AnimationStopped   += (x, y) =>
            {
                _shadowLayer.Opacity = _arcLayer.Opacity = _pathOpacityDownAnimation.GetToAs <NSNumber>().FloatValue;
            };
        }
コード例 #23
0
        private void SetupStrokeAnimation()
        {
            if (null == _strokeAnimation)
            {
                _strokeAnimation = CABasicAnimation.FromKeyPath("strokeEnd");
                _strokeAnimation.AnimationStopped += (x, y) =>
                {
                    if (_strokeAnimation.RemovedOnCompletion)
                    {
                        // Disable animation because the CALayer will attempt to animate
                        // the stroke from the PREVIOUS StrokeEnd value (not the currently animated value).
                        CATransaction.DisableActions = true;
                        _arcLayer.StrokeEnd          = this.ProgressValue;
                        CATransaction.DisableActions = false;
                    }
                    else
                    {
                        // Reinitialize animation parameters
                        SetupStrokeAnimation();

                        if (IsIndeterminate)
                        {
                            _arcLayer.AddAnimation(_strokeAnimation, ANIMATION_STROKE);
                        }
                        else if (null != _arcLayer.AnimationForKey(ANIMATION_STROKE))
                        {
                            // If the animation is currently running, let's phase it out.
                            // Ending at the current 'Progress Value'.
                            _strokeAnimation.To       = NSNumber.FromNFloat(this.ProgressValue);
                            _strokeAnimation.Duration = _rotationAnimation.Duration * 1.5f;
                            // ...then have it removed so it no longer recurs.
                            _strokeAnimation.RemovedOnCompletion = true;
                            // Queue it up for one final animation...
                            _arcLayer.AddAnimation(_strokeAnimation, ANIMATION_STROKE);
                        }
                    }
                };
            }


            var presentationLayer = _arcLayer.PresentationLayer as CAShapeLayer ?? _arcLayer;

            if (presentationLayer.StrokeEnd > 0.75f)
            {
                _strokeAnimation.From = NSNumber.FromNFloat(presentationLayer.StrokeEnd);//NSNumber.FromNFloat(0.1f);
                _strokeAnimation.To   = NSNumber.FromNFloat(0.1f);
            }
            else if (presentationLayer.StrokeEnd > 0.1f)
            {
                _strokeAnimation.From = NSNumber.FromNFloat(presentationLayer.StrokeEnd);//NSNumber.FromNFloat(0.75f);
                _strokeAnimation.To   = NSNumber.FromNFloat(0.1f);
            }
            else
            {
                _strokeAnimation.From = NSNumber.FromNFloat(presentationLayer.StrokeEnd);//NSNumber.FromNFloat(0.1f);
                _strokeAnimation.To   = NSNumber.FromNFloat(0.75f);
            }

            _strokeAnimation.Duration            = _rotationAnimation.Duration * 1.5f;
            _strokeAnimation.Cumulative          = true;
            _strokeAnimation.FillMode            = CAFillMode.Forwards;
            _strokeAnimation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            _strokeAnimation.RemovedOnCompletion = false;
        }
コード例 #24
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.Gray;

            var progressView = new CircularProgressView();

            progressView.TrackTintColor = UIColor.Clear;
            View.AddSubview(progressView);

            var labeledProgressView = new LabeledCircularProgressView();

            labeledProgressView.RoundedCorners = true;
            View.AddSubview(labeledProgressView);

            var pieProgressView = new CircularProgressView();

            pieProgressView.ProgressTintColor = UIColor.Yellow;
            pieProgressView.TrackTintColor    = UIColor.Black;
            pieProgressView.ThicknessRatio    = 1.0f;
            View.AddSubview(pieProgressView);

            var indeterminateProgressView = new CircularProgressView();

            indeterminateProgressView.Progress = 0.35f;
            indeterminateProgressView.IndeterminateDuration = 1.0f;
            indeterminateProgressView.Indeterminate         = true;
            View.AddSubview(indeterminateProgressView);

            // constraints
            progressView.MakeConstraints(make => {
                make.CenterX.EqualTo(View.CenterX());
                make.Top.EqualTo(this.TopLayoutGuideBottom()).Offset(12.0f);
                make.Width.EqualTo(NSNumber.FromNFloat(60));
                make.Height.EqualTo(NSNumber.FromNFloat(60));
            });
            labeledProgressView.MakeConstraints(make => {
                make.CenterX.EqualTo(View.CenterX());
                make.Top.EqualTo(progressView.Bottom()).Offset(12.0f);
                make.Width.EqualTo(NSNumber.FromNFloat(60));
                make.Height.EqualTo(NSNumber.FromNFloat(60));
            });
            pieProgressView.MakeConstraints(make => {
                make.CenterX.EqualTo(View.CenterX());
                make.Top.EqualTo(labeledProgressView.Bottom()).Offset(12.0f);
                make.Width.EqualTo(NSNumber.FromNFloat(60));
                make.Height.EqualTo(NSNumber.FromNFloat(60));
            });
            indeterminateProgressView.MakeConstraints(make => {
                make.CenterX.EqualTo(View.CenterX());
                make.Top.EqualTo(pieProgressView.Bottom()).Offset(12.0f);
                make.Width.EqualTo(NSNumber.FromNFloat(60));
                make.Height.EqualTo(NSNumber.FromNFloat(60));
            });

            var progress = -0.1f;

            Task.Run(async() => {
                while (true)
                {
                    if (progress >= 1.0f)
                    {
                        progress = 0.0f;
                    }
                    else
                    {
                        progress += 0.1f;
                    }

                    InvokeOnMainThread(() => {
                        progressView.SetProgress(progress, true);
                        pieProgressView.SetProgress(progress, true);

                        labeledProgressView.SetProgress(progress, true);
                        labeledProgressView.ProgressLabel.Text = progress.ToString("0%");
                    });

                    if (progress <= 0.0f)
                    {
                        await Task.Delay(1500);
                    }
                    else
                    {
                        await Task.Delay(400);
                    }
                }
            });
        }
コード例 #25
0
        void FadeInBackgroundAndRippleTapCircle()
        {
            if (IsColorClear(BackgroundColor))
            {
                if (TapCircleColor == null)
                {
                    TapCircleColor = UsesSmartColor ? TitleLabel.TextColor.ColorWithAlpha(ClearBackgroundDumbTapCircleColor.CGColor.Alpha) : ClearBackgroundDumbTapCircleColor;
                }

                if (BackgroundFadeColor == null)
                {
                    BackgroundFadeColor = UsesSmartColor ? TitleLabel.TextColor.ColorWithAlpha(ClearBackgroundDumbFadeColor.CGColor.Alpha) : ClearBackgroundDumbFadeColor;
                }

                BackgroundColorFadeLayer.BackgroundColor = BackgroundFadeColor.CGColor;

                float startingOpacity = BackgroundColorFadeLayer.Opacity;

                if (BackgroundColorFadeLayer.AnimationKeys != null &&
                    BackgroundColorFadeLayer.AnimationKeys.Length > 0 &&
                    BackgroundColorFadeLayer.PresentationLayer != null)
                {
                    startingOpacity = BackgroundColorFadeLayer.PresentationLayer.Opacity;
                }

                CABasicAnimation fadeBackgroundDarker = CABasicAnimation.FromKeyPath("opacity");
                fadeBackgroundDarker.Duration       = TouchDownAnimationDuration;
                fadeBackgroundDarker.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                fadeBackgroundDarker.SetFrom(NSNumber.FromNFloat(startingOpacity));
                fadeBackgroundDarker.SetTo(NSNumber.FromNFloat(1));
                fadeBackgroundDarker.FillMode            = CAFillMode.Forwards;
                fadeBackgroundDarker.RemovedOnCompletion = !false;
                BackgroundColorFadeLayer.Opacity         = 1;

                BackgroundColorFadeLayer.AddAnimation(fadeBackgroundDarker, "animateOpacity");
            }
            else
            {
                if (TapCircleColor == null)
                {
                    TapCircleColor = UsesSmartColor ? TitleLabel.TextColor.ColorWithAlpha(DumbTapCircleFillColor.CGColor.Alpha) : DumbTapCircleFillColor;
                }
            }

            nfloat tapCircleFinalDiameter = CalculateTapCircleFinalDiameter();

            var tapCircleLayerSizerView = new UIView(new CGRect(0, 0, tapCircleFinalDiameter, tapCircleFinalDiameter));

            tapCircleLayerSizerView.Center = RippleFromTapLocation ? TapPoint : new CGPoint(Bounds.GetMidX(), Bounds.GetMidY());

            var startingRectSizerView = new UIView(new CGRect(0, 0, TapCircleDiameterStartValue, TapCircleDiameterStartValue));

            startingRectSizerView.Center = tapCircleLayerSizerView.Center;

            UIBezierPath startingCirclePath = UIBezierPath.FromRoundedRect(startingRectSizerView.Frame, TapCircleDiameterStartValue / 2f);

            var endingRectSizerView = new UIView(new CGRect(0, 0, tapCircleFinalDiameter, tapCircleFinalDiameter));

            endingRectSizerView.Center = tapCircleLayerSizerView.Center;

            UIBezierPath endingCirclePath = UIBezierPath.FromRoundedRect(endingRectSizerView.Frame, tapCircleFinalDiameter / 2f);

            CAShapeLayer tapCircle = new CAShapeLayer();

            tapCircle.FillColor   = TapCircleColor.CGColor;
            tapCircle.StrokeColor = UIColor.Clear.CGColor;
            tapCircle.BorderColor = UIColor.Clear.CGColor;
            tapCircle.BorderWidth = 0;
            tapCircle.Path        = startingCirclePath.CGPath;

            if (!RippleBeyondBounds)
            {
                CAShapeLayer mask = new CAShapeLayer();
                mask.Path        = UIBezierPath.FromRoundedRect(FadeAndClippingMaskRect, CornerRadius).CGPath;
                mask.FillColor   = UIColor.Black.CGColor;
                mask.StrokeColor = UIColor.Clear.CGColor;
                mask.BorderColor = UIColor.Clear.CGColor;
                mask.BorderWidth = 0;

                tapCircle.Mask = mask;
            }

            RippleAnimationQueue.AddObjects(new NSObject[] { tapCircle });
            Layer.InsertSublayerAbove(tapCircle, BackgroundColorFadeLayer);

            CABasicAnimation tapCircleGrowthAnimation = CABasicAnimation.FromKeyPath("path");

            tapCircleGrowthAnimation.Duration       = TouchDownAnimationDuration;
            tapCircleGrowthAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            tapCircleGrowthAnimation.SetFrom(startingCirclePath.CGPath);
            tapCircleGrowthAnimation.SetTo(endingCirclePath.CGPath);
            tapCircleGrowthAnimation.FillMode            = CAFillMode.Forwards;
            tapCircleGrowthAnimation.RemovedOnCompletion = false;

            CABasicAnimation fadeIn = CABasicAnimation.FromKeyPath("opacity");

            fadeIn.Duration       = TouchDownAnimationDuration;
            fadeIn.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
            fadeIn.SetFrom(NSNumber.FromNFloat(0));
            fadeIn.SetTo(NSNumber.FromNFloat(1));
            fadeIn.FillMode            = CAFillMode.Forwards;
            fadeIn.RemovedOnCompletion = false;

            tapCircle.AddAnimation(tapCircleGrowthAnimation, "animatePath");
            tapCircle.AddAnimation(fadeIn, "opacityAnimation");
        }
コード例 #26
0
ファイル: DailyGraphView.cs プロジェクト: blparr/XWeather
        void drawLines()
        {
            layer.RemoveAllAnimations();

            var dot = new CGRect(0, 0, lineWidth, lineWidth);

            nfloat x, y;

            CGPoint start = CGPoint.Empty;
            CGPoint end   = CGPoint.Empty;


            // Draw curved graph line
            using (UIColor color = UIColor.White.ColorWithAlpha(0.25f), dotColor = UIColor.Clear) {
                using (CGPath path = new CGPath()) {
                    var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2);

                    for (int i = 0; i < count; i++)
                    {
                        // adjusted index
                        var ai = i;

                        double temp;

                        if (hourly)
                        {
                            temp = HourlyTemps [ai];
                        }
                        else
                        {
                            // reset start when switching from highs to lows
                            if (i == Forecasts.Count)
                            {
                                start = CGPoint.Empty;
                            }

                            var highs = i < Forecasts.Count;

                            ai = highs ? i : i - Forecasts.Count;

                            temp = highs ? HighTemps [ai] : LowTemps [ai];
                        }

                        var percent = ((nfloat)temp - scaleLow) / scaleRange;


                        x = padding + inset + (ai * scaleX);

                        y = graphRect.GetMaxY() - (graphRect.Height * percent);

                        end = new CGPoint(x, y);


                        if (!hourly)
                        {
                            dot.X = end.X - (lineWidth / 2);
                            dot.Y = end.Y - (lineWidth / 2);

                            path.AddEllipseInRect(dot);
                        }


                        if (start == CGPoint.Empty)
                        {
                            path.MoveToPoint(end);
                        }
                        else
                        {
                            path.MoveToPoint(start);

                            if (hourly)
                            {
                                path.AddLineToPoint(end);
                            }
                            else
                            {
                                var diff = (end.X - start.X) / 2;

                                path.AddCurveToPoint(end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y);
                            }
                        }

                        start = end;
                    }

                    // add line path to context
                    layer.Path = path;

                    layer.LineWidth   = lineWidth;
                    layer.StrokeColor = color.CGColor;
                    layer.FillColor   = dotColor.CGColor;

                    CABasicAnimation pathAnimation = new CABasicAnimation {
                        KeyPath = "strokeEnd"
                    };
                    pathAnimation.Duration = 1.0;
                    pathAnimation.From     = NSNumber.FromNFloat(0);
                    pathAnimation.To       = NSNumber.FromNFloat(1);
                    layer.AddAnimation(pathAnimation, "strokeEndAnimation");
                }
            }
        }
コード例 #27
0
        public void Reload()
        {
            Container.RemoveConstraints(Container.Constraints);
            foreach (var v in Container.Subviews)
            {
                v.RemoveFromSuperview();
            }

            var format  = "V:|";
            var views   = new NSMutableDictionary();
            var metrics = new NSMutableDictionary();

            if (Toolbar != null)
            {
                metrics["toolbarTop"]    = NSNumber.FromNFloat(ToolbarEdgeInsets.Top);
                metrics["toolbarBottom"] = NSNumber.FromNFloat(ToolbarEdgeInsets.Bottom);

                format          += "-(toolbarTop)-[toolbar]-(toolbarBottom)";
                views["toolbar"] = Toolbar;
                Container.Layout(Toolbar).Horizontally(ToolbarEdgeInsets.Left, ToolbarEdgeInsets.Right);
            }

            if (ContentView != null)
            {
                metrics["contentViewBottom"] = NSNumber.FromNFloat(ContentViewEdgeInsets.Bottom);

                if (Toolbar != null)
                {
                    metrics["toolbarBottom"] = NSNumber.FromNFloat((metrics["toolbarBottom"] as NSNumber).NFloatValue + ContentViewEdgeInsets.Top);
                    format += "-[contentView]-(contentViewBottom)";
                }
                else
                {
                    metrics["contentViewTop"] = NSNumber.FromNFloat(ContentViewEdgeInsets.Top);
                    format += "-(contentViewTop)-[contentView]-(contentViewBottom)";
                }

                views["contentView"] = ContentView;
                Container.Layout(ContentView).Horizontally(ContentViewEdgeInsets.Left, ContentViewEdgeInsets.Right);

                ContentView.Grid().Reload();
                ContentView.Divider().Reload();
            }

            if (BottomBar != null)
            {
                metrics["bottomBarBottom"] = NSNumber.FromNFloat(BottomBarEdgeInsets.Bottom);

                if (ContentView != null)
                {
                    metrics["contentViewBottom"] = NSNumber.FromNFloat((metrics["contentViewBottom"] as NSNumber).FloatValue + BottomBarEdgeInsets.Top);
                    format += "-[bottomBar]-(bottomBarBottom)";
                }
                else if (Toolbar != null)
                {
                    metrics["toolbarBottom"] = NSNumber.FromNFloat((metrics["toolbarBottom"] as NSNumber).FloatValue + BottomBarEdgeInsets.Top);
                    format += "-[bottomBar]-(bottomBarBottom)";
                }
                else
                {
                    metrics["bottomBarTop"] = NSNumber.FromNFloat(BottomBarEdgeInsets.Top);
                    format += "-(bottomBarTop)-[bottomBar]-(bottomBarBottom)";
                }

                views["bottomBar"] = BottomBar;
                Container.Layout(BottomBar).Horizontally(BottomBarEdgeInsets.Left, BottomBarEdgeInsets.Right);
            }

            if (views.Count > 0)
            {
                Container.AddConstraints(Layout.Constraint(string.Format("{0}-|", format), 0, metrics, views));
            }

            //if (TitleLabel != null)
            //{
            //	verticalFormat += "-(insetTop)";
            //	metrics["insetTop"] = NSNumber.FromNFloat(ContentInset.Top + TitleLabelInset.Top);
            //}
            //else if (ContentView != null)
            //{
            //	verticalFormat += "-(insetTop)";
            //	metrics["insetTop"] = NSNumber.FromNFloat(ContentInset.Top + ContentViewEdgeInsets.Top);
            //}

            //if (TitleLabel != null)
            //{
            //	verticalFormat += "-[titleLabel]";
            //	views["titleLabel"] = TitleLabel;

            //	this.Layout(TitleLabel).Horizontally(left: ContentInset.Left + TitleLabelInset.Left, right: ContentInset.Right + TitleLabelInset.Right);
            //}

            //if (ContentView != null)
            //{
            //	if (TitleLabel == null)
            //	{
            //		metrics["insetTop"] = NSNumber.FromNFloat((metrics["insetTop"] as NSNumber).NFloatValue + ContentViewEdgeInsets.Top);
            //	}
            //	else
            //	{
            //		verticalFormat += "-(insetB)";
            //		metrics["insetB"] = NSNumber.FromNFloat(TitleLabelInset.Bottom + ContentViewEdgeInsets.Top);
            //	}
            //	verticalFormat += "-[contentView]";
            //	views["contentView"] = ContentView;

            //	this.Layout(ContentView).Horizontally(left: ContentInset.Left + ContentViewEdgeInsets.Left, right: ContentInset.Right + ContentViewEdgeInsets.Right);
            //}

            //if (LeftButtons != null && LeftButtons.Length > 0)
            //{
            //	var h = "H:|";
            //	var d = new NSMutableDictionary();
            //	var i = 0;
            //	foreach (var b in LeftButtons)
            //	{
            //		var k = String.Format("b{0}", i);
            //		d[k] = b;

            //		if (i == 0)
            //		{
            //			h += "-(left)-";
            //		}
            //		else
            //		{
            //			h += "-(left_right)-";
            //		}

            //		h += String.Format("[{0}]", k);

            //		this.Layout(b).Bottom(ContentInset.Bottom + LeftButtonsInset.Bottom);

            //		i += 1;
            //	}

            //	AddConstraints(Layout.Constraint(h, 0, NSDictionary.FromObjectsAndKeys(
            //		new object[] { ContentInset.Left + LeftButtonsInset.Left, LeftButtonsInset.Left + LeftButtonsInset.Right },
            //		new object[] { "left", "left_right" }
            //	), d));
            //}

            //if (RightButtons != null && RightButtons.Length > 0)
            //{
            //	var h = "H:|";
            //	var d = new NSMutableDictionary();
            //	var i = RightButtons.Length - 1;
            //	foreach (var b in LeftButtons)
            //	{
            //		var k = String.Format("b{0}", i);
            //		d[k] = b;

            //		if (i == 0)
            //		{
            //			h += "-(right)-";
            //		}
            //		else
            //		{
            //			h += "-(right_left)-";
            //		}

            //		h += String.Format("[{0}]", k);

            //		this.Layout(b).Bottom(ContentInset.Bottom + RightButtonsInset.Bottom);

            //		i -= 1;
            //	}

            //	AddConstraints(Layout.Constraint(h + "|", 0, NSDictionary.FromObjectsAndKeys(
            //		new object[] { ContentInset.Right + RightButtonsInset.Right, RightButtonsInset.Right + RightButtonsInset.Left },
            //		new object[] { "right", "right_left" }
            //	), d));
            //}

            //if (LeftButtons != null && LeftButtons.Length > 0)
            //{
            //	verticalFormat += "-(insetC)-[button]";
            //	views["button"] = LeftButtons[0];
            //	metrics["insetC"] = NSNumber.FromNFloat(LeftButtonsInset.Top);
            //	metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + LeftButtonsInset.Bottom);
            //}
            //else if (RightButtons != null && RightButtons.Length > 0)
            //{
            //	verticalFormat += "-(insetC)-[button]";
            //	views["button"] = RightButtons[0];
            //	metrics["insetC"] = NSNumber.FromNFloat(RightButtonsInset.Top);
            //	metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + RightButtonsInset.Bottom);
            //}

            //if (ContentView != null)
            //{
            //	if (metrics["insetC"] == null)
            //	{
            //		metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + ContentViewEdgeInsets.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //	else
            //	{
            //		metrics["insetC"] = NSNumber.FromNFloat((metrics["insetC"] as NSNumber).NFloatValue + ContentViewEdgeInsets.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //}
            //else if (TitleLabel != null)
            //{
            //	if (metrics["insetC"] == null)
            //	{
            //		metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + TitleLabelInset.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //	else
            //	{
            //		metrics["insetC"] = NSNumber.FromNFloat((metrics["insetC"] as NSNumber).NFloatValue + TitleLabelInset.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //}
            //else if (metrics["insetC"] != null)
            //{
            //	metrics["insetC"] = NSNumber.FromNFloat((metrics["insetC"] as NSNumber).NFloatValue + ContentInset.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //}

            //if (views.Count > 0)
            //{
            //	verticalFormat += "-(insetBottom)-|";

            //	AddConstraints(Layout.Constraint(verticalFormat, 0, metrics, views));
            //}
        }
コード例 #28
0
        void LowerButtonAndFadeOutBackground()
        {
            if (IsRaised)
            {
                nfloat startRadius  = LiftedShadowRadius;
                nfloat startOpacity = LiftedShadowOpacity;
                CGPath startPath    = UIBezierPath.FromRoundedRect(UpRect, CornerRadius).CGPath;

                if (Layer.AnimationKeys != null && Layer.AnimationKeys.Length > 0)
                {
                    startRadius  = Layer.PresentationLayer.ShadowRadius;
                    startOpacity = Layer.PresentationLayer.ShadowOpacity;
                    startPath    = Layer.PresentationLayer.ShadowPath;
                }

                CABasicAnimation decreaseRadius = CABasicAnimation.FromKeyPath("shadowRadius");
                decreaseRadius.SetFrom(NSNumber.FromNFloat(startRadius));
                decreaseRadius.SetTo(NSNumber.FromNFloat(LoweredShadowRadius));
                decreaseRadius.Duration            = TouchUpAnimationDuration;
                decreaseRadius.FillMode            = CAFillMode.Forwards;
                decreaseRadius.RemovedOnCompletion = true;
                Layer.ShadowRadius = LoweredShadowRadius;

                CABasicAnimation shadowOpacityAnimation = CABasicAnimation.FromKeyPath("shadowOpacity");
                shadowOpacityAnimation.Duration = TouchUpAnimationDuration;
                shadowOpacityAnimation.SetFrom(NSNumber.FromNFloat(startOpacity));
                shadowOpacityAnimation.SetTo(NSNumber.FromNFloat(LoweredShadowOpacity));
                shadowOpacityAnimation.FillMode            = CAFillMode.Backwards;
                shadowOpacityAnimation.RemovedOnCompletion = true;
                Layer.ShadowOpacity = LoweredShadowOpacity;

                CABasicAnimation shadowAnimation = CABasicAnimation.FromKeyPath("shadowPath");
                shadowAnimation.Duration = TouchUpAnimationDuration;
                shadowAnimation.SetFrom(startPath);
                shadowAnimation.SetTo(UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath);
                shadowAnimation.FillMode            = CAFillMode.Forwards;
                shadowAnimation.RemovedOnCompletion = true;
                Layer.ShadowPath = UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath;


                Layer.AddAnimation(shadowAnimation, "shadow");
                Layer.AddAnimation(decreaseRadius, "shadowRadius");
                Layer.AddAnimation(shadowOpacityAnimation, "shadowOpacity");
            }

            if (IsColorClear(BackgroundColor))
            {
                nfloat startingOpacity = BackgroundColorFadeLayer.Opacity;

                if (BackgroundColorFadeLayer.AnimationKeys != null &&
                    BackgroundColorFadeLayer.AnimationKeys.Length > 0 &&
                    BackgroundColorFadeLayer.PresentationLayer != null)
                {
                    startingOpacity = BackgroundColorFadeLayer.PresentationLayer.Opacity;
                }

                CABasicAnimation removeFadeBackgroundDarker = CABasicAnimation.FromKeyPath("opacity");
                removeFadeBackgroundDarker.Duration       = TouchUpAnimationDuration;
                removeFadeBackgroundDarker.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                removeFadeBackgroundDarker.SetFrom(NSNumber.FromNFloat(startingOpacity));
                removeFadeBackgroundDarker.SetTo(NSNumber.FromNFloat(0));
                removeFadeBackgroundDarker.FillMode            = CAFillMode.Forwards;
                removeFadeBackgroundDarker.RemovedOnCompletion = !false;
                BackgroundColorFadeLayer.Opacity = 0;

                BackgroundColorFadeLayer.AddAnimation(removeFadeBackgroundDarker, "animateOpacity");
            }
        }
コード例 #29
0
        protected MessageTableViewCell(IntPtr handle)
            : base(handle)
        {
            SelectionStyle  = UITableViewCellSelectionStyle.None;
            BackgroundColor = UIColor.White;


            TitleLabel = new UILabel();
            TitleLabel.TranslatesAutoresizingMaskIntoConstraints = false;
            TitleLabel.BackgroundColor        = UIColor.Clear;
            TitleLabel.UserInteractionEnabled = false;
            TitleLabel.Lines     = 0;
            TitleLabel.TextColor = UIColor.Gray;
            TitleLabel.Font      = UIFont.BoldSystemFontOfSize(DefaultFontSize);

            BodyLabel = new UILabel();
            BodyLabel.TranslatesAutoresizingMaskIntoConstraints = false;
            BodyLabel.BackgroundColor        = UIColor.Clear;
            BodyLabel.UserInteractionEnabled = false;
            BodyLabel.Lines     = 0;
            BodyLabel.TextColor = UIColor.DarkGray;
            BodyLabel.Font      = UIFont.SystemFontOfSize(DefaultFontSize);

            ThumbnailView = new UIImageView();
            ThumbnailView.TranslatesAutoresizingMaskIntoConstraints = false;
            ThumbnailView.UserInteractionEnabled = false;
            ThumbnailView.BackgroundColor        = UIColor.FromWhiteAlpha(0.9f, 1.0f);
            ThumbnailView.Layer.CornerRadius     = AvatarHeight / 2.0f;
            ThumbnailView.Layer.MasksToBounds    = true;


            ContentView.AddSubview(ThumbnailView);
            ContentView.AddSubview(TitleLabel);
            ContentView.AddSubview(BodyLabel);

            var views = NSDictionary.FromObjectsAndKeys(new NSObject[] {
                ThumbnailView,
                TitleLabel,
                BodyLabel
            }, new NSObject[] {
                (NSString)"thumbnailView",
                (NSString)"titleLabel",
                (NSString)"bodyLabel"
            });

            var metrics = NSDictionary.FromObjectsAndKeys(new [] {
                NSNumber.FromNFloat(AvatarHeight),
                NSNumber.FromNFloat(15f),
                NSNumber.FromNFloat(10f),
                NSNumber.FromNFloat(5f),
                NSNumber.FromNFloat(80f)
            }, new [] {
                "thumbSize",
                "padding",
                "right",
                "left",
                "attchSize"
            });

            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-left-[thumbnailView(thumbSize)]-right-[titleLabel(>=0)]-right-|", 0, metrics, views));
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-left-[thumbnailView(thumbSize)]-right-[bodyLabel(>=0)]-right-|", 0, metrics, views));
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-right-[titleLabel(>=0@999)]-left-[bodyLabel(>=0@999)]-left-|", 0, metrics, views));
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-right-[thumbnailView(thumbSize)]-(>=0)-|", 0, metrics, views));
        }