Ejemplo n.º 1
0
        public void LayersToCenter(AnimationPacket _animatePacket)
        {
            CABasicAnimation _aniLayersToCenter;
            AnimateDelegate  _myAnimateDelegate = new AnimateDelegate();

            var pt = _animatePacket.Layer1.Position;

            _animatePacket.Layer1.Position = _animatePacket.ToPosition1;
            _animatePacket.Layer2.Position = _animatePacket.ToPosition1;

            // ** Position Animation
            _aniLayersToCenter = CABasicAnimation.FromKeyPath("position");
            // ** These two set if the presentation layer will stay set in the final animated position
            _aniLayersToCenter.RemovedOnCompletion = true;
            //_aniLayersToCenter.FillMode = CAFillMode.Forwards;
            _aniLayersToCenter.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);

            _aniLayersToCenter.Delegate = _myAnimateDelegate;
            _aniLayersToCenter.From     = NSValue.FromCGPoint(pt);
            _aniLayersToCenter.To       = NSValue.FromCGPoint(_animatePacket.ToPosition1);
            _aniLayersToCenter.Duration = 0.5f;



            _animatePacket.Layer1.AddAnimation(_aniLayersToCenter, "position");
            _animatePacket.Layer2.AddAnimation(_aniLayersToCenter, "position");
        }
Ejemplo n.º 2
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            //Creates basic moving animation
            var pt = layer.Position;

            layer.Position = new CGPoint(100, 300);
            var basicAnimation = CABasicAnimation.FromKeyPath("position");

            basicAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            basicAnimation.From           = NSValue.FromCGPoint(pt);
            basicAnimation.To             = NSValue.FromCGPoint(new CGPoint(100, 300));


            //Creates transformation animation
            layer.Transform = CATransform3D.MakeRotation((float)Math.PI * 2, 0, 0, 1);
            var animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform");

            animRotate.Values = new NSObject[] {
                NSNumber.FromFloat(0f),
                NSNumber.FromFloat((float)Math.PI / 2f),
                NSNumber.FromFloat((float)Math.PI),
                NSNumber.FromFloat((float)Math.PI * 2)
            };
            animRotate.ValueFunction = CAValueFunction.FromName(CAValueFunction.RotateX);

            //Adds the animations to a group, and adds the group to the layer
            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Duration   = 2;
            animationGroup.Animations = new CAAnimation[] { basicAnimation, animRotate };
            layer.AddAnimation(animationGroup, null);
        }
Ejemplo n.º 3
0
        NSObject IInterpolator.ProvideValue(double delta)
        {
            var tdx = To.X - From.X;
            var tdy = To.Y - From.Y;

            return(NSValue.FromCGPoint(new CGPoint(tdx * delta + From.X, tdy * delta + From.Y)));
        }
        private static NSValue[] GeneratePDFPointLines(String pointStr)
        {
            List <CGPoint> pointList = null;

            // New way
            if (pointStr.StartsWith("["))
            {
                int pdfPointIdx = pointStr.IndexOf(StringRef.pdfPoints);
                if (pdfPointIdx >= 0)
                {
                    pointStr = pointStr.Remove(0, pdfPointIdx + 11);
                }

                pointList = Convert2PointList(pointStr);
            }
            else
            {
                // Old way
                pointList = GeneratePointF(pointStr);
            }

            if (pointList != null && pointList.Count > 0)
            {
                NSValue[] valueArray = new NSValue[pointList.Count];
                for (int i = 0; i < valueArray.Length; i++)
                {
                    valueArray[i] = NSValue.FromCGPoint(pointList[i]);
                }

                return(valueArray);
            }

            return(null);
        }
Ejemplo n.º 5
0
        public static SkeletonLayerAnimation MakeSlidingAnimation(GradientDirection direction, double duration = 1.5)
        {
            return((layer) =>
            {
                var startValues = direction.StartPoint();
                var endValues = direction.EndPoint();

                var startPointAnim = CABasicAnimation.FromKeyPath(nameof(CAGradientLayer.StartPoint));
                startPointAnim.From = NSValue.FromCGPoint(startValues.from);
                startPointAnim.To = NSValue.FromCGPoint(startValues.to);

                var endPointAnim = CABasicAnimation.FromKeyPath(nameof(CAGradientLayer.EndPoint));
                endPointAnim.From = NSValue.FromCGPoint(endValues.from);
                endPointAnim.To = NSValue.FromCGPoint(endValues.to);

                var animGroup = new CAAnimationGroup
                {
                    Animations = new[] { startPointAnim, endPointAnim },
                    Duration = duration,
                    TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn),
                    RepeatCount = float.MaxValue
                };
                return animGroup;
            });
        }
        void MoveLogoToTopLeft()
        {
            if (Cancelled)
            {
                return;
            }

            var rotate = CABasicAnimation.FromKeyPath("transform.rotation");

            rotate.From = NSObject.FromObject(0);
            rotate.To   = NSObject.FromObject(Math.PI * 2);

            var liftAndSlide = CABasicAnimation.FromKeyPath("position");

            liftAndSlide.From = NSValue.FromCGPoint(SlinkLogoImageView.Layer.Position);
            liftAndSlide.To   = NSValue.FromCGPoint(new CGPoint(40, 75));

            var shrink = CABasicAnimation.FromKeyPath("transform.scale");

            shrink.To = NSNumber.FromDouble(0.5);

            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Animations          = new CAAnimation[] { rotate, liftAndSlide, shrink };
            animationGroup.Duration            = animationDuration / 2;
            animationGroup.FillMode            = CAFillMode.Forwards;
            animationGroup.RemovedOnCompletion = false;
            rotate.RepeatCount = 0;

            SlinkLogoImageView.Layer.AddAnimation(animationGroup, "MoveLogoToTopLeft");
        }
Ejemplo n.º 7
0
        void HideMenuLayerAnimation(NSString timingFunctionName = null)
        {
            CGRect f               = _shadowLayer.Frame;
            var    group           = new CAAnimationGroup();
            var    animationOffset = new CABasicAnimation();

            animationOffset.KeyPath = new NSString("position");
            animationOffset.From    = NSValue.FromCGPoint(new CGPoint(f.GetMidX(), f.GetMidY()));
            animationOffset.To      = NSValue.FromCGPoint(new CGPoint(f.GetMidX() - UIScreen.MainScreen.Bounds.Width * _targetViewControllerOffset, f.GetMidY()));

            var animationScaleX = new CABasicAnimation();

            animationScaleX.KeyPath = new NSString("transform.scale.x");
            animationScaleX.From    = NSValue.FromObject(0.8f);
            animationScaleX.To      = NSValue.FromObject(1.0f);

            var animationScaleY = new CABasicAnimation();

            animationScaleY.KeyPath = new NSString("transform.scale.y");
            animationScaleY.From    = NSValue.FromObject(0.8f);
            animationScaleY.To      = NSValue.FromObject(1.0f);

            //during pan gesture animation curve should be linear
            //In other cases EaseInOut
            group.TimingFunction = CAMediaTimingFunction.FromName(timingFunctionName ?? CAMediaTimingFunction.EaseInEaseOut);
            group.Duration       = TransitionDurationTime;
            group.Animations     = new[] { animationOffset, animationScaleX, animationScaleY };

            _shadowLayer.AddAnimation(group, "HideShadowLayerAnimation");
        }
        public void CreateResultAnimation(UITextField resultValue, string AnimationKey = "position")
        {
            var theAnimation = new CABasicAnimation();

            theAnimation.Duration = 3.0;
            theAnimation.SetFrom(NSValue.FromCGPoint(new CGPoint(182, 342)));
            theAnimation.SetTo(NSValue.FromCGPoint(new CGPoint(182, 400)));
            theAnimation.AutoReverses = true;
            resultValue.Layer.AddAnimation(theAnimation, AnimationKey);
        }
        public static void ShakeIt(UIView label, float Duration = 0.05f, int RepeatCount = 60, float MovementDistance = 2f, string AnimationKey = "position")
        {
            CABasicAnimation animation = new CABasicAnimation();

            animation.Duration     = Duration;
            animation.RepeatCount  = RepeatCount;
            animation.AutoReverses = true;
            animation.SetFrom(NSValue.FromCGPoint(new CGPoint(label.Center.X - MovementDistance, label.Center.Y - MovementDistance)));
            animation.SetTo(NSValue.FromCGPoint(new CGPoint(label.Center.X + MovementDistance, label.Center.Y + MovementDistance)));
            label.Layer.AddAnimation(animation, AnimationKey);
        }
Ejemplo n.º 10
0
        public void MoveToPosition(CGPoint newPos)
        {
            var posAnim = CABasicAnimation.FromKeyPath("position");

            posAnim.From           = NSValue.FromCGPoint(Position);
            posAnim.To             = NSValue.FromCGPoint(newPos);
            posAnim.Duration       = (newPos.IsEmpty) ? 0.2f : 0.4f;
            posAnim.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Default);
            AddAnimation(posAnim, "position");
            Position = newPos;
        }
Ejemplo n.º 11
0
        public static void Shake(this UIView view, double duration = 0.05, int repeatCount = 5, double shakeThreshold = 4.0)
        {
            var animation = CABasicAnimation.FromKeyPath("position");
            animation.Duration = duration;
            animation.RepeatCount = repeatCount;
            animation.AutoReverses = true;
            animation.From =
                NSValue.FromCGPoint(new CGPoint(view.Center.X - shakeThreshold, view.Center.Y));

            animation.To = NSValue.FromCGPoint(new CGPoint(view.Center.X + shakeThreshold, view.Center.Y));
            view.Layer.AddAnimation(animation, "shake");
        }
Ejemplo n.º 12
0
        public void LayersToEdge(AnimationPacket _animatePacket)
        {
            CABasicAnimation _aniLayersToEdge;
            CABasicAnimation _aniLayersToEdgeFade;
            CAAnimationGroup _animationGroup = new CAAnimationGroup();

            AnimateDelegate _myAnimateDelegate = new AnimateDelegate();

            var     pt = _animatePacket.Layer1.Position;
            CGPoint x;

            if (_animatePacket.DirectionY == G__NumberDisplayPositionY.Top)
            {
                _animatePacket.Layer1.Position = _animatePacket.ToPosition1;
                _animatePacket.Layer2.Position = _animatePacket.ToPosition1;
                x = _animatePacket.ToPosition1;
            }
            else
            {
                _animatePacket.Layer1.Position = _animatePacket.ToPosition2;
                _animatePacket.Layer2.Position = _animatePacket.ToPosition2;
                x = _animatePacket.ToPosition2;
            }

            _aniLayersToEdge = CABasicAnimation.FromKeyPath("position");
            // ** These two set if the presentation layer will stay set in the final animated position
            _aniLayersToEdge.RemovedOnCompletion = true;
            _aniLayersToEdge.FillMode            = CAFillMode.Forwards;
            _aniLayersToEdge.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
            _aniLayersToEdge.Delegate            = _myAnimateDelegate;
            _aniLayersToEdge.From = NSValue.FromCGPoint(pt);
            _aniLayersToEdge.To   = NSValue.FromCGPoint(x);
            //_aniLayersToEdge.Duration = 1.0f;
            //_aniLayersToEdge.RepeatCount = 1.0f;

            // ** Fade Animation
            _aniLayersToEdgeFade = CABasicAnimation.FromKeyPath("opacity");
            // ** These two set if the presentation layer will stay set in the final animated position
            _aniLayersToEdgeFade.RemovedOnCompletion = true;
            _aniLayersToEdgeFade.FillMode            = CAFillMode.Forwards;
            _aniLayersToEdgeFade.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
            _aniLayersToEdgeFade.Delegate            = _myAnimateDelegate;
            _aniLayersToEdgeFade.From = NSNumber.FromFloat(1.0f);
            _aniLayersToEdgeFade.To   = NSNumber.FromFloat(0.0f);
            //_aniLayersToCenter.Duration = 1.0f;

            var y = NWAnimations.SpinLogo();

            _animationGroup.Duration   = 0.5f;
            _animationGroup.Animations = new CAAnimation[] { _aniLayersToEdgeFade, _aniLayersToEdge, y };
            _animatePacket.Layer1.AddAnimation(_animationGroup, null);
            _animatePacket.Layer2.AddAnimation(_animationGroup, null);
        }
        private static CABasicAnimation ShimmerSlideAnimation(double duration, ShimmeringDirection direction)
        {
            CABasicAnimation animation = CABasicAnimation.FromKeyPath("position");

            animation.To          = NSValue.FromCGPoint(CGPoint.Empty);
            animation.Duration    = duration;
            animation.RepeatCount = float.MaxValue;
            if (direction == ShimmeringDirection.Left || direction == ShimmeringDirection.Up)
            {
                animation.Speed = -(float)Math.Abs(animation.Speed);
            }

            return(animation);
        }
Ejemplo n.º 14
0
        public AnnotationsFromCodeViewController(NSUrl document) : base(new PSPDFDocument(document))
        {
            // Sets the Delegate to listen for 'IPSPDFViewControllerDelegate' events like 'DidSelectAnnotations'.
            // Any NSObject derived class can be set to 'Delegate' property as long as it implements 'IPSPDFViewControllerDelegate'.
            Delegate = this;

            Document.Title = "Programmatically create annotations";
            Document.AnnotationSaveMode = PSPDFAnnotationSaveMode.Disabled;

            var    annotationsList = new List <PSPDFAnnotation> ();
            uint   targetPage      = 0;
            var    pageInfo        = Document.GetPageInfo(targetPage);
            CGRect viewRect        = UIScreen.MainScreen.Bounds;
            var    maxHeight       = pageInfo.Size.Height;

            for (int i = 0; i < 5; i++)
            {
                var note = new PSPDFNoteAnnotation {
                    // width/height will be ignored for note annotations.
                    BoundingBox = new CGRect(100, (50 + i * maxHeight / 5), 32, 32),
                    Contents    = string.Format("Note {0}", (5 - i))                   // notes are added bottom-up
                };
                annotationsList.Add(note);
            }

            // Ink Annotation sample
            var inkAnnot = new PSPDFInkAnnotation();
            var linesArr = NSArray <NSValue> .FromNSObjects(
                NSValue.FromCGPoint(new CGPoint(480.93079f, 596.0625f)),
                NSValue.FromCGPoint(new CGPoint(476.8027f, 592.96881f)),
                NSValue.FromCGPoint(new CGPoint(468.54639f, 585.75f)),
                NSValue.FromCGPoint(new CGPoint(456.1619f, 574.40631f)),
                NSValue.FromCGPoint(new CGPoint(436.5531f, 550.6875f)),
                NSValue.FromCGPoint(new CGPoint(357.086f, 434.15631f)),
                NSValue.FromCGPoint(new CGPoint(294.1315f, 359.90631f)),
                NSValue.FromCGPoint(new CGPoint(226.01691f, 284.625f)),
                NSValue.FromCGPoint(new CGPoint(176.4789f, 222.75f))
                );

            var lines = new NSArray <NSValue> [] { linesArr };

            inkAnnot.Lines     = PSPDFInkAnnotation.ConvertViewLinesToPdfLines(lines, pageInfo, viewRect);
            inkAnnot.LineWidth = 5;
            inkAnnot.Color     = UIColor.White;
            annotationsList.Add(inkAnnot);

            annotationsArr = annotationsList.ToArray();
            Document.AddAnnotations(annotationsArr, options: null);
        }
        public void MoveUp(nfloat distance)
        {
            var move = CABasicAnimation.FromKeyPath("position");

            move.From = NSValue.FromCGPoint(Position);
            move.To   = NSValue.FromCGPoint(new CGPoint(Position.X, Position.Y - distance));

            move.Duration       = MoveUpDuration;
            move.TimingFunction = TimingFunction;

            move.FillMode            = CAFillMode.Forwards;
            move.RemovedOnCompletion = false;

            AddAnimation(move, move.KeyPath);
        }
Ejemplo n.º 16
0
        public static CABasicAnimation Position(CGPoint point, double?duration = null)
        {
            var animation = CABasicAnimation.FromKeyPath("position");

            animation.To = NSValue.FromCGPoint(point);

            animation.FillMode            = Convert.MaterialAnimationFillModeToValue(MaterialAnimationFillMode.Forwards);
            animation.RemovedOnCompletion = false;
            animation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            if (duration != null)
            {
                animation.Duration = duration.Value;
            }
            return(animation);
        }
Ejemplo n.º 17
0
        partial void repositionImages(NSObject sender)
        {
            foreach (CALayer layer in View.Layer.Sublayers)
            {
                if (layer == textContainer || layer == repositionButton.Layer || layer == durationTextField.Layer)
                {
                    continue;
                }

                CGRect imageBounds = layer.Bounds;

                nfloat X, Y = 0;
                if (windowIsResizing)
                {
                    X = layer.Position.X + ((layer.Position.X - imageBounds.Size.Width / 2) / (lastWindowSize.Width - imageBounds.Size.Width) * (Window.Frame.Width - lastWindowSize.Width));
                    Y = layer.Position.Y + ((layer.Position.Y - imageBounds.Size.Height / 2) / (lastWindowSize.Height - imageBounds.Size.Height) * (Window.Frame.Height - lastWindowSize.Height));
                }
                else
                {
                    X = (nfloat)random.Next((int)Math.Floor(imageBounds.Width / 2), (int)Math.Floor(layer.SuperLayer.Bounds.GetMaxX() - imageBounds.Width / 2));
                    Y = (nfloat)random.Next((int)Math.Floor(imageBounds.Height / 2), (int)Math.Floor(layer.SuperLayer.Bounds.GetMaxY() - imageBounds.Height / 2));
                }
                CGPoint newPoint = new CGPoint(X, Y);

                CAMediaTimingFunction tr      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                CAMediaTimingFunction tf      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                CABasicAnimation      posAnim = CABasicAnimation.FromKeyPath("position");
                posAnim.From           = NSValue.FromCGPoint(layer.Position);
                posAnim.Duration       = windowIsResizing ? 0 : durationTextField.FloatValue;
                posAnim.TimingFunction = windowIsResizing ? tr : tf;

                CABasicAnimation zPosAnim = CABasicAnimation.FromKeyPath("zPosition");
                zPosAnim.From           = NSNumber.FromDouble(layer.ZPosition);
                zPosAnim.Duration       = durationTextField.FloatValue;
                zPosAnim.TimingFunction = tf;

                layer.Actions = NSDictionary.FromObjectsAndKeys(new NSObject[] { posAnim, zPosAnim }, new NSObject[] { new NSString("position"), new NSString("zPosition") });

                CATransaction.Begin();
                layer.Position = newPoint;
                if (!windowIsResizing)
                {
                    layer.ZPosition = random.Next(-100, 99);
                }
                CATransaction.Commit();
            }
        }
Ejemplo n.º 18
0
        public void SlideButtonIn()
        {
            CABasicAnimation slide = CABasicAnimation.FromKeyPath("position");

            slide.From     = NSValue.FromCGPoint(new CGPoint(-100.0f, btnShowTime.Layer.Position.Y));
            slide.To       = NSValue.FromCGPoint(btnShowTime.Layer.Position);
            slide.Duration = 1.0f;

            //Set the timing function
            CAMediaTimingFunction tf = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

            slide.TimingFunction    = tf;
            slide.AnimationStopped += FadeRepeat;

            // Kick off the animation by adding it to the layer
            btnShowTime.Layer.AddAnimation(slide, "slideAnimation");
        }
Ejemplo n.º 19
0
        void ShowMenuCancelLayerAnimation(double offset)
        {
            var group = new CAAnimationGroup();

            var animationOffset = new CABasicAnimation();

            animationOffset.KeyPath = new NSString("position");
            //Calculate position of shadow layer's X when animation was cancelled
            var offsetX   = UIScreen.MainScreen.Bounds.Width * _targetViewControllerOffset;
            var originalX = _shadowLayer.Frame.GetMidX() - ((offset / TransitionDurationTime) * offsetX);

            //Start animatiom from cancelled X position
            animationOffset.From = NSValue.FromCGPoint(new CGPoint(originalX, _shadowLayer.Frame.GetMidY()));
            //to position when animation began
            animationOffset.To = NSValue.FromCGPoint(new CGPoint(_shadowLayer.Frame.GetMidX(), _shadowLayer.Frame.GetMidY()));

            var scaleDiff = _targetViewControllerInitialScale - _targetViewControllerEndScale;
            //scaling of view when animation was cancelled
            var cancelledScalePosition = _targetViewControllerInitialScale - (scaleDiff - (offset / TransitionDurationTime) * scaleDiff);

            //Animate x/y positions from size when was cancelled
            //To size before interaction begin
            var animationScaleX = new CABasicAnimation();

            animationScaleX.KeyPath = new NSString("transform.scale.x");
            animationScaleX.From    = NSValue.FromObject(cancelledScalePosition);
            animationScaleX.To      = NSValue.FromObject(_targetViewControllerEndScale);

            var animationScaleY = new CABasicAnimation();

            animationScaleY.KeyPath = new NSString("transform.scale.y");
            animationScaleY.From    = NSValue.FromObject(cancelledScalePosition);
            animationScaleY.To      = NSValue.FromObject(_targetViewControllerEndScale);

            group.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);

            //It's pretty much random
            //with small animation time, it's looks good
            //With long animation time it's not really fit, but still not so bad
            group.Duration            = offset / 6;
            group.FillMode            = CAFillMode.Forwards;
            group.RemovedOnCompletion = false;
            group.Animations          = new[] { animationScaleX, animationScaleY, animationOffset };

            _shadowLayer.AddAnimation(group, "ShowScaleLayerAnimation");
        }
        public override void TouchesMoved(Foundation.NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);

            // Loop all touch positions
            foreach (var touch in touches)
            {
                // Get the current and last points
                var points = new NSMutableDictionary();

                points.Add(new NSString("currentPoint"), NSValue.FromCGPoint(((UITouch)touch).LocationInView(this)));
                points.Add(new NSString("lastPoint"), NSValue.FromCGPoint(((UITouch)touch).PreviousLocationInView(this)));

                // Draw
                PerformSelector(new Selector("DrawLine:"), points, 0.0f);
            }
        }
Ejemplo n.º 21
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            var pt = layer.Position;

            layer.Position = new CGPoint(150, 350);

            var basicAnimation = CABasicAnimation.FromKeyPath("position");

            basicAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            basicAnimation.From           = NSValue.FromCGPoint(pt);
            basicAnimation.To             = NSValue.FromCGPoint(new CGPoint(150, 350));
            basicAnimation.Duration       = 2;

            layer.AddAnimation(basicAnimation, "position");
        }
Ejemplo n.º 22
0
        void ShowMenuOffsetShadowLayerAnimation()
        {
            var f = _shadowLayer.Frame;
            var animationOffset = new CABasicAnimation();

            animationOffset.KeyPath             = new NSString("position");
            animationOffset.From                = NSValue.FromCGPoint(new CGPoint(f.GetMidX(), f.GetMidY()));
            animationOffset.To                  = NSValue.FromCGPoint(new CGPoint(f.GetMidX() + UIScreen.MainScreen.Bounds.Width * _targetViewControllerOffset, f.GetMidY()));
            animationOffset.Duration            = TransitionDurationTime;
            animationOffset.FillMode            = CAFillMode.Forwards;
            animationOffset.RemovedOnCompletion = false;
            animationOffset.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            //Must set layer frame explicitly, to animate it back when menu will hide
            f.X += UIScreen.MainScreen.Bounds.Width * _targetViewControllerOffset;
            _shadowLayer.Frame = f;

            _shadowLayer.AddAnimation(animationOffset, "ShowOffsetLayerAnimation");
        }
        void ShakeViewLeftAndRight(UIView view)
        {
            if (Cancelled)
            {
                return;
            }

            var shake = CABasicAnimation.FromKeyPath("position");

            shake.Duration            = animationDuration;
            shake.FillMode            = CAFillMode.Forwards;
            shake.RemovedOnCompletion = false;
            shake.RepeatCount         = 9999;
            shake.AutoReverses        = true;
            shake.From = NSValue.FromCGPoint(new CGPoint(view.Frame.GetMidX() - 10, view.Frame.GetMidY()));
            shake.To   = NSValue.FromCGPoint(new CGPoint(view.Frame.GetMidX() + 10, view.Frame.GetMidY()));
            view.Layer.AddAnimation(shake, "Shake");
        }
        public AnnotationsFromCodeViewController(NSData documentData) : base(new PSPDFDocument(documentData))
        {
            Document.Title = "Programmatically create annotations";
            Document.AnnotationSaveMode = PSPDFAnnotationSaveMode.Disabled;

            var annotationsList = new List <PSPDFAnnotation> ();
            var maxHeight       = Document.GetPageInfo(0).RotatedRect.Size.Height;

            for (int i = 0; i < 5; i++)
            {
                var note = new PSPDFNoteAnnotation()
                {
                    // width/height will be ignored for note annotations.
                    BoundingBox = new CGRect(100, (50 + i * maxHeight / 5), 32, 32),
                    Contents    = string.Format("Note {0}", (5 - i))                   // notes are added bottom-up
                };
                annotationsList.Add(note);
            }

            // Ink Annotation sample
            var inkAnnot = new PSPDFInkAnnotation();

            inkAnnot.Lines = new List <NSValue[]> ()
            {
                new [] {
                    NSValue.FromCGPoint(new CGPoint(480.93079f, 596.0625f)),
                    NSValue.FromCGPoint(new CGPoint(476.8027f, 592.96881f)),
                    NSValue.FromCGPoint(new CGPoint(468.54639f, 585.75f)),
                    NSValue.FromCGPoint(new CGPoint(456.1619f, 574.40631f)),
                    NSValue.FromCGPoint(new CGPoint(436.5531f, 550.6875f)),
                    NSValue.FromCGPoint(new CGPoint(357.086f, 434.15631f)),
                    NSValue.FromCGPoint(new CGPoint(294.1315f, 359.90631f)),
                    NSValue.FromCGPoint(new CGPoint(226.01691f, 284.625f)),
                    NSValue.FromCGPoint(new CGPoint(176.4789f, 222.75f))
                }
            };
            inkAnnot.LineWidth = 5;
            inkAnnot.Color     = UIKit.UIColor.White;
            annotationsList.Add(inkAnnot);

            annotationsArr = annotationsList.ToArray();
            Document.AddAnnotations(annotationsArr, null);
        }
        void MoveCardBetweenPhones(UIView card, double duration, CGPoint destination)
        {
            if (Cancelled)
            {
                return;
            }

            var rotate = CABasicAnimation.FromKeyPath("transform.rotation");

            rotate.From = NSObject.FromObject(0);
            rotate.To   = NSObject.FromObject(Math.PI * 2);

            var liftAndSlideRight = CABasicAnimation.FromKeyPath("position");

            liftAndSlideRight.To = NSValue.FromCGPoint(destination);
            liftAndSlideRight.RemovedOnCompletion = false;
            liftAndSlideRight.FillMode            = CAFillMode.Forwards;

            var grow = CABasicAnimation.FromKeyPath("transform.scale");

            grow.To                  = NSNumber.FromDouble(7.5);
            grow.Duration            = animationDuration / 2;
            grow.RemovedOnCompletion = false;
            grow.FillMode            = CAFillMode.Forwards;

            var shrink = CABasicAnimation.FromKeyPath("transform.scale");

            shrink.To                  = NSNumber.FromDouble(3.0);
            shrink.BeginTime           = animationDuration / 2;
            shrink.RemovedOnCompletion = false;
            shrink.FillMode            = CAFillMode.Forwards;

            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Animations          = new CAAnimation[] { rotate, liftAndSlideRight, grow, shrink };
            animationGroup.Duration            = duration;
            animationGroup.FillMode            = CAFillMode.Forwards;
            animationGroup.RemovedOnCompletion = false;
            rotate.RepeatCount = 0;

            card.Layer.AddAnimation(animationGroup, "MoveCardBetweenPhones");
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            PopButton.TouchUpInside += (object sender, EventArgs e) => {
                var springAnimation = POPSpringAnimation.AnimationWithPropertyNamed(POPAnimation.ViewCenter);
                var newCenter       = PopButton.Center;
                newCenter.Y                      = newCenter.Y + 200;
                springAnimation.ToValue          = NSValue.FromCGPoint(newCenter);
                springAnimation.CompletionAction = (POPAnimation arg1, bool arg2) => {
                    var decayAnimation = POPDecayAnimation.AnimationWithPropertyNamed(POPAnimation.LayerPositionY);
                    decayAnimation.Velocity      = new NSNumber(-800);
                    decayAnimation.AutoReverse   = true;
                    decayAnimation.RepeatForever = true;
                    decayAnimation.ClampMode     = POPAnimationClampFlags.Both;
                    PopButton.AddAnimation(decayAnimation, "Decay");
                };
                PopButton.AddAnimation(springAnimation, "Center");
            };
        }
        public void MoveDown(nfloat distance)
        {
            var move = CABasicAnimation.FromKeyPath("position");

            move.From = NSValue.FromCGPoint(new CGPoint(Position.X, Position.Y - distance));
            move.To   = NSValue.FromCGPoint(Position);

            move.Duration       = MoveUpDuration;
            move.TimingFunction = TimingFunction;

            move.FillMode            = CAFillMode.Forwards;
            move.RemovedOnCompletion = false;
            move.AnimationStopped   += delegate
            {
                if (didEndAnimation != null)
                {
                    didEndAnimation();
                }
            };
            AddAnimation(move, move.KeyPath);
        }
Ejemplo n.º 28
0
        public static CAAnimation Sliding(this CALayer This)
        {
            var startPointAnim = CABasicAnimation.FromKeyPath("startPoint");

            startPointAnim.From = NSValue.FromCGPoint(new CGPoint(-1, -0.5f));
            startPointAnim.To   = NSValue.FromCGPoint(new CGPoint(1, 0.5f));

            var endPointAnim = CABasicAnimation.FromKeyPath("endPoint");

            endPointAnim.From = NSValue.FromCGPoint(new CGPoint(0, 0.5f));
            endPointAnim.To   = NSValue.FromCGPoint(new CGPoint(2, 0.5f));

            var animGroup = new CAAnimationGroup
            {
                Animations     = new[] { startPointAnim, endPointAnim },
                Duration       = 1.5f,
                TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut),
                RepeatCount    = float.MaxValue
            };

            return(animGroup);
        }
        public void SlideButtonIn()
        {
            // Create a basic animation
            CABasicAnimation slide = CABasicAnimation.FromKeyPath("position");

            //Set the starting point for the slide in, from off the left side of the screen
            slide.From = NSValue.FromCGPoint(new PointF(-100.0f, btnShowTime.Layer.Position.Y));
            // Set the destination position, get frmo the modal layer of the show time button (btnShowTime)
            slide.To = NSValue.FromCGPoint(btnShowTime.Layer.Position);
            // How long the slide in will take
            slide.Duration = 1.0f;

            //Set the timing function to ease in/ease out rather than a fully linear animation
            CAMediaTimingFunction tf = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

            slide.TimingFunction = tf;
            // After slide in is complete, start fading the show time button (btnShowTime) in and out
            slide.AnimationStopped += FadeRepeat;

            // Kick off the animation by adding it to the CALayer
            btnShowTime.Layer.AddAnimation(slide, "slideAnimation");
        }
Ejemplo n.º 30
0
        public AnimationBuilder MoveBy(CGPoint position, double delaySeconds, double durationSeconds)
        {
            //  position
            var positionAnimation = CABasicAnimation.FromKeyPath("position");

            positionAnimation.TimingFunction = this.EasingFunction;
            if (durationSeconds > 0)
            {
                positionAnimation.Duration = durationSeconds;
            }
            if (delaySeconds > 0)
            {
                positionAnimation.BeginTime = delaySeconds;
            }
            positionAnimation.FillMode            = CAFillMode.Forwards;
            positionAnimation.RemovedOnCompletion = false;
            positionAnimation.By = NSValue.FromCGPoint(position);

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

            return(this);
        }