Esempio n. 1
0
        public void applyGravity(object sender, EventArgs e)
        {
            animator = new UIDynamicAnimator(chart.PlotView);

            TKChartVisualPoint[] points = chart.VisualPointsForSeries(chart.Series [0]);

            for (int i = 0; i < points.Length; i++)
            {
                TKChartVisualPoint point  = points [i];
                CGPoint            center = originalValues [i];
                if (point.Animator != null)
                {
                    point.Animator.RemoveAllBehaviors();
                    point.Animator = null;
                }
                point.Center = center;
            }

            UICollisionBehavior collision = new UICollisionBehavior(points);

            collision.TranslatesReferenceBoundsIntoBoundary = true;

            UIGravityBehavior gravity = new UIGravityBehavior(points);

            gravity.GravityDirection = new CGVector(0.0f, 2.0f);

            UIDynamicItemBehavior dynamic = new UIDynamicItemBehavior(points);

            dynamic.Elasticity = 0.5f;

            animator.AddBehavior(dynamic);
            animator.AddBehavior(gravity);
            animator.AddBehavior(collision);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			var collisionBehavior = new UICollisionBehavior (square);
			collisionBehavior.TranslatesReferenceBoundsIntoBoundary = true;

			var squareCenterPoint = new PointF (square.Center.X, square.Center.Y - 100);
			var attachmentOffset = new UIOffset (-25.0f, -25.0f);

			/*
    		 By default, an attachment behavior uses the center of a view. By using a small offset, 
    		 we get a more interesting effect which will cause the view to have rotation movement 
    		 when dragging the attachment.
    		*/
			var attachmentBehavior = new UIAttachmentBehavior (square, attachmentOffset, squareCenterPoint);

			// Show visually the attachment points
			redSquare.Center = attachmentBehavior.AnchorPoint;
			blueSquare.Center = new PointF (25.0f, 25.0f);

			Animator = new UIDynamicAnimator (View);
			Animator.AddBehavior (attachmentBehavior);

			View.AddGestureRecognizer (new UIPanGestureRecognizer ((gesture) => {
				attachmentBehavior.AnchorPoint = gesture.LocationInView (View);
				redSquare.Center = attachmentBehavior.AnchorPoint;
			}));
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			/*
     			We want to show collisions between views and boundaries with different 
     			elasticities, we thus associate the two views to gravity and collision 
     			behaviors. We will only change the restitution parameter for one of 
     			these views.
     		*/
			var gravityBehavior = new UIGravityBehavior (square1, square2);

			var collisionBehavior = new UICollisionBehavior (square1, square2) {
				TranslatesReferenceBoundsIntoBoundary = true
			};
			collisionBehavior.BeganBoundaryContact += (sender, e) => {
				((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray;
			};
			collisionBehavior.EndedBoundaryContact += (sender, e) => {
				((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray;
			};

			var propertiesBehavior = new UIDynamicItemBehavior (square2) {
				Elasticity = 0.5f
			};
	
			Animator = new UIDynamicAnimator (View);
			Animator.AddBehaviors (gravityBehavior, collisionBehavior, propertiesBehavior);
		}
Esempio n. 4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var Gravedad = new UIGravityBehavior(Imagen1);//Se agrega gravedad a uno de los objectos.
            var Colision = new UICollisionBehavior(Imagen2)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };

            var PuntoCentral = new CGPoint(Imagen1.Center.X,
                                           Imagen1.Center.Y -
                                           100);

            var Anclaje = new UIAttachmentBehavior(Imagen1, PuntoCentral) //Se conecta la imagen al punto centra
            {
                Frequency = 1.0f,
                Damping   = 0.1f //forma en la que esta haciendo el rebote.
            };

            Imagen2.Center = Anclaje.AnchorPoint;
            Imagen2.Center = new CGPoint(50.0f, 50.0f);
            Animador       = new UIDynamicAnimator(View);
            Animador.AddBehaviors(Anclaje, Gravedad, Colision);
            View.AddGestureRecognizer(new UIPanGestureRecognizer((gesto) =>
            {
                Anclaje.AnchorPoint = gesto.LocationInView(View);
                Imagen2.Center      = Anclaje.AnchorPoint;
            }));
        }
Esempio n. 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var screenBounds = UIScreen.MainScreen.Bounds;
            var length       = Math.Floor(0.1 * Math.Max(screenBounds.Width, screenBounds.Height));

            itemView = new UIView(new CGRect(0.0, 0.0, length, Math.Floor(length / ItemAspectRatio)))
            {
                AutoresizingMask = UIViewAutoresizing.None,
                BackgroundColor  = UIColor.Red
            };

            var panGestureRecognizer = new UIPanGestureRecognizer(Pan);

            itemView.AddGestureRecognizer(panGestureRecognizer);
            View.AddSubview(itemView);

            var longPressGestureRecognizer = new UILongPressGestureRecognizer(LongPress);

            View.AddGestureRecognizer(longPressGestureRecognizer);

            animator       = new UIDynamicAnimator(View);
            stickyBehavior = new StickyCornersBehavior(itemView, (float)length * 0.5f);
            animator.AddBehavior(stickyBehavior);
        }
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

            if (selectedPoint == null)
            {
                return;
            }

            UISnapBehavior snap = new UISnapBehavior(selectedPoint, originalPosition);

            snap.Damping = 0.2f;

            UIPushBehavior push = new UIPushBehavior(new IUIDynamicItem[] { selectedPoint }, UIPushBehaviorMode.Instantaneous);

            push.PushDirection = new CGVector(0.0f, -1.0f);
            push.Magnitude     = 0.001f;

            UIDynamicAnimator animator = new UIDynamicAnimator();

            animator.AddBehavior(snap);
            animator.AddBehavior(push);

            selectedPoint.Animator = animator;
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			using (image = UIImage.FromFile ("monkeys.jpg")) {

				imageView = new UIImageView (new CGRect (new CGPoint (View.Center.X - image.Size.Width / 2, 0), image.Size)) {
					Image =  image
				};

				View.AddSubview (imageView);

				// 1. create the dynamic animator
				dynAnimator = new UIDynamicAnimator (this.View);

				// 2. create behavior(s)
				var dynItems = new IUIDynamicItem[] { imageView };
				var gravity = new UIGravityBehavior (dynItems);
				var collision = new UICollisionBehavior (dynItems) {
					TranslatesReferenceBoundsIntoBoundary = true
				};
				var dynBehavior = new UIDynamicItemBehavior (dynItems) {
					Elasticity = 0.7f
				};

				// 3. add behaviors(s) to the dynamic animator
				dynAnimator.AddBehavior (gravity);
				dynAnimator.AddBehavior (collision);
				dynAnimator.AddBehavior (dynBehavior);
			}
		}
        public void applyGravity(object sender, EventArgs e)
        {
            animator = new UIDynamicAnimator (chart.PlotView);

            TKChartVisualPoint[] points = chart.VisualPointsForSeries (chart.Series [0]);

            for (int i=0; i<points.Length; i++) {
                TKChartVisualPoint point = points [i];
                CGPoint center = originalValues [i];
                if (point.Animator != null) {
                    point.Animator.RemoveAllBehaviors();
                    point.Animator = null;
                }
                point.Center = center;
            }

            UICollisionBehavior collision = new UICollisionBehavior (points);
            collision.TranslatesReferenceBoundsIntoBoundary = true;

            UIGravityBehavior gravity = new UIGravityBehavior (points);
            gravity.GravityDirection = new CGVector (0.0f, 2.0f);

            UIDynamicItemBehavior dynamic = new UIDynamicItemBehavior (points);
            dynamic.Elasticity = 0.5f;

            animator.AddBehavior(dynamic);
            animator.AddBehavior(gravity);
            animator.AddBehavior(collision);
        }
        public override void WillMoveToAnimator(UIDynamicAnimator targetAnimator)
        {
            base.WillMoveToAnimator(targetAnimator);
            var bounds = targetAnimator.ReferenceView.Bounds;

            UpdateFieldsInBounds(bounds);
        }
Esempio n. 10
0
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

            if (selectedPoint == null)
            {
                return;
            }

            UITouch touch      = (UITouch)touches.AnyObject;
            CGPoint touchPoint = touch.LocationInView(chart.PlotView);
            CGPoint delta      = new CGPoint(originalLocation.X, originalLocation.Y - touchPoint.Y);

            UISnapBehavior snap = new UISnapBehavior(selectedPoint, originalPosition);

            snap.Damping = 0.2f;

            UIPushBehavior push = new UIPushBehavior(new IUIDynamicItem[] { selectedPoint }, UIPushBehaviorMode.Instantaneous);

            push.PushDirection = new CGVector(0.0f, delta.Y > 0 ? -1.0f : -1.0f);
            push.Magnitude     = 0.001f;

            UIDynamicAnimator animator = new UIDynamicAnimator();

            animator.AddBehavior(snap);
            animator.AddBehavior(push);

            selectedPoint.Animator = animator;
        }
Esempio n. 11
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            TKChartVisualPoint[] points = chart.VisualPointsForSeries(chart.Series [0]);
            originalValues = new List <CGPoint> ();
            foreach (TKChartVisualPoint p in points)
            {
                originalValues.Add(p.CGPoint);
            }
            TKChartVisualPoint point = points[4];

            UISnapBehavior snap = new UISnapBehavior(point, point.Center);

            snap.Damping = 0.2f;

            UIPushBehavior push = new UIPushBehavior(new IUIDynamicItem[] { point }, UIPushBehaviorMode.Instantaneous);

            push.PushDirection = new CGVector(0.0f, -1.0f);
            push.Magnitude     = 0.003f;

            UIDynamicAnimator animator = new UIDynamicAnimator();

            animator.AddBehavior(snap);
            animator.AddBehavior(push);

            point.Animator = animator;
        }
Esempio n. 12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            using (image = UIImage.FromFile("monkeys.jpg")) {
                imageView = new UIImageView(new CGRect(new CGPoint(View.Center.X - image.Size.Width / 2, 0), image.Size))
                {
                    Image = image
                };

                View.AddSubview(imageView);

                // 1. create the dynamic animator
                dynAnimator = new UIDynamicAnimator(this.View);

                // 2. create behavior(s)
                var dynItems  = new IUIDynamicItem[] { imageView };
                var gravity   = new UIGravityBehavior(dynItems);
                var collision = new UICollisionBehavior(dynItems)
                {
                    TranslatesReferenceBoundsIntoBoundary = true
                };
                var dynBehavior = new UIDynamicItemBehavior(dynItems)
                {
                    Elasticity = 0.7f
                };

                // 3. add behaviors(s) to the dynamic animator
                dynAnimator.AddBehavior(gravity);
                dynAnimator.AddBehavior(collision);
                dynAnimator.AddBehavior(dynBehavior);
            }
        }
        protected void DynamicAnimatorDidPause(UIDynamicAnimator animator)
        {
            this.Animator.RemoveAllBehaviors();

            _collision = null;
            _topView   = null;
            _push      = null;
            _gravity   = null;
            _composite = null;
            _animator  = null;

            this.SlidingViewController.TopViewController.View.UserInteractionEnabled = true;

            UIViewController topController = this.SlidingViewController.GetViewControllerForKey(ECSlidingViewController.ECTransitionContextTopViewControllerKey);

            if ((_panningRight && _positiveLeftToRight) || (!_panningRight && !_positiveLeftToRight))
            {
                topController.View.Frame = this.SlidingViewController.GetFinalFrameForViewController(topController);
                this.SlidingViewController.FinishInteractiveTransition();
            }
            else if ((_panningRight && !_positiveLeftToRight) || (!_panningRight && _positiveLeftToRight))
            {
                topController.View.Frame = this.SlidingViewController.GetInitialFrameForViewController(topController);
                this.SlidingViewController.CancelInteractiveTransition();
            }

            this.SlidingViewController.CompleteTransition(true);
        }
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     Animator = new UIDynamicAnimator(View);
     //agrega un comportammiento al UIView  en este caso se aplica la animacion de gravedad
     Animator.AddBehavior(new UIGravityBehavior(square));
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var collisionBehavior = new UICollisionBehavior(square)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };

            var squareCenterPoint = new CGPoint(square.Center.X, square.Center.Y - 100.0f);
            var attachmentOffset  = new UIOffset(-25.0f, -25.0f);

            /*
             * By default, an attachment behavior uses the center of a view. By using a small offset,
             * we get a more interesting effect which will cause the view to have rotation movement
             * when dragging the attachment.
             */
            var attachmentBehavior = new UIAttachmentBehavior(square, attachmentOffset, squareCenterPoint);

            // Show visually the attachment points
            redSquare.Center  = attachmentBehavior.AnchorPoint;
            blueSquare.Center = new CGPoint(25.0f, 25.0f);

            Animator = new UIDynamicAnimator(View);
            Animator.AddBehavior(attachmentBehavior);

            View.AddGestureRecognizer(new UIPanGestureRecognizer((gesture) => {
                attachmentBehavior.AnchorPoint = gesture.LocationInView(View);
                redSquare.Center = attachmentBehavior.AnchorPoint;
            }));
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			var gravityBehavior = new UIGravityBehavior (square);

			var collisionBehavior = new UICollisionBehavior (square) {
				TranslatesReferenceBoundsIntoBoundary = true
			};
			collisionBehavior.BeganBoundaryContact += (sender, e) => {
				((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray;
			};
			collisionBehavior.EndedBoundaryContact += (sender, e) => {
				((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray;
			};

			var squareCenterPoint = new CGPoint (square.Center.X, square.Center.Y - 100);

			var attachmentBehavior = new UIAttachmentBehavior (square, squareCenterPoint) {
				Frequency = 1.0f,
				Damping = 0.1f
			};

			redSquare.Center = attachmentBehavior.AnchorPoint;
			blueSquare.Center = new CGPoint (50.0f, 50.0f);

			Animator = new UIDynamicAnimator (View);
			Animator.AddBehaviors (attachmentBehavior, gravityBehavior, collisionBehavior);

			View.AddGestureRecognizer (new UIPanGestureRecognizer ((gesture) => {
				attachmentBehavior.AnchorPoint = gesture.LocationInView (View);
				redSquare.Center = attachmentBehavior.AnchorPoint;
			}));
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            /*
             * We want to show collisions between views and boundaries with different
             * elasticities, we thus associate the two views to gravity and collision
             * behaviors. We will only change the restitution parameter for one of
             * these views.
             */
            var gravityBehavior = new UIGravityBehavior(square1, square2);

            var collisionBehavior = new UICollisionBehavior(square1, square2)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };

            collisionBehavior.BeganBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray;
            };
            collisionBehavior.EndedBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray;
            };

            var propertiesBehavior = new UIDynamicItemBehavior(square2)
            {
                Elasticity = 0.5f
            };

            Animator = new UIDynamicAnimator(View);
            Animator.AddBehaviors(gravityBehavior, collisionBehavior, propertiesBehavior);
        }
Esempio n. 18
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //se crea un punto con base a la vista
            //var squareCenterPoint = new CGPoint (square.Center.X, square.Center.Y - 100.0f);

            var squareCenterPoint = new CGPoint(llanta.Center.X, llanta.Center.Y - 100.0f);

            //Representa un desplazamiento de posición. Los valores positivos están a la derecha y abajo.
            var attachmentOffset = new UIOffset(-25.0f, -25.0f);

            /*
             * By default, an attachment behavior uses the center of a view. By using a small offset,
             * we get a more interesting effect which will cause the view to have rotation movement
             * when dragging the attachment.
             */
            //var attachmentBehavior = new UIAttachmentBehavior (square, attachmentOffset, squareCenterPoint);
            var attachmentBehavior = new UIAttachmentBehavior(llanta, attachmentOffset, squareCenterPoint);

            // Muestra los puntos de fijacion
            redSquare.Center  = attachmentBehavior.AnchorPoint;
            blueSquare.Center = new CGPoint(25.0f, 25.0f);

            //se agrega la vista al dynamicAnimator donde gestiona todos los compatamientos de los objetos
            Animator = new UIDynamicAnimator(View);
            Animator.AddBehavior(attachmentBehavior);


            //Este gesto es de arrastrar
            View.AddGestureRecognizer(new UIPanGestureRecognizer((gesture) => {
                attachmentBehavior.AnchorPoint = gesture.LocationInView(View);
                redSquare.Center = attachmentBehavior.AnchorPoint;
            }));
        }
Esempio n. 19
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Animador = new UIDynamicAnimator(View);               //Se asigna a la vista actual.

            Animador.AddBehavior(new UIGravityBehavior(Imagen1)); //Se agrega un comportamiento
        }
Esempio n. 20
0
        public SpringyCollectionViewFlowLayout()
        {
            this.MinimumInteritemSpacing = margin;

            this.MinimumLineSpacing = margin;
            this.ItemSize           = new SizeF(100, 100);
            dynamicAnimator         = new UIDynamicAnimator(this);
        }
        public SpringyCollectionViewFlowLayout()
        {
            this.MinimumInteritemSpacing = margin;

            this.MinimumLineSpacing = margin;
            this.ItemSize = new SizeF(100,100);
            dynamicAnimator = new UIDynamicAnimator (this);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			View.AddGestureRecognizer (new UITapGestureRecognizer ((gesture) => {
				Animator = new UIDynamicAnimator (View);
				Animator.AddBehavior (new UISnapBehavior (square, gesture.LocationInView (View)));
			}));
		}
Esempio n. 23
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.AddGestureRecognizer(new UITapGestureRecognizer((gesture) => {
                Animator = new UIDynamicAnimator(View);
                Animator.AddBehavior(new UISnapBehavior(square, gesture.LocationInView(View)));
            }));
        }
        public void applyGravity()
        {
            if (firstTime)
            {
                firstTime = false;

                TKChartVisualPoint[] points1 = chart.VisualPointsForSeries(chart.Series [0]);
                originalValues = new List <CGPoint> ();
                foreach (TKChartVisualPoint p in points1)
                {
                    originalValues.Add(p.CGPoint);
                }
                TKChartVisualPoint point1 = points1 [4];
                originalLocation = point1.Center;
            }
            // >> chart-anim-gravity-cs
            animator = new UIDynamicAnimator(chart.PlotView);
            TKChartVisualPoint[] points = chart.VisualPointsForSeries(chart.Series [0]);
            TKChartVisualPoint   point  = points [4];

            for (int i = 0; i < originalValues.Count; i++)
            {
                TKChartVisualPoint pt = points [i];
                if (pt.Animator != null)
                {
                    pt.Animator.RemoveAllBehaviors();
                    pt.Animator = null;
                }
                pt.Center = ((CGPoint)originalValues[i]);
            }

            point.Center = new CGPoint(originalLocation.X, 0);

            UICollisionBehavior collision = new UICollisionBehavior(points);

            collision.TranslatesReferenceBoundsIntoBoundary = true;

            UIGravityBehavior gravity = new UIGravityBehavior(points);

            gravity.GravityDirection = new CGVector(0.0f, 2.0f);

            UIDynamicItemBehavior dynamic = new UIDynamicItemBehavior(points);

            dynamic.Elasticity = 0.5f;

            animator.AddBehavior(dynamic);
            animator.AddBehavior(gravity);
            animator.AddBehavior(collision);
            // << chart-anim-gravity-cs
        }
Esempio n. 25
0
        private void SetUpBehaviours()
        {
            animator            = new UIDynamicAnimator(this);
            animator.Delegate   = this;
            verticesAttachments = new VertexAttachmentBehaviour[3];
            centersAttachments  = new VertexAttachmentBehaviour[3];

            for (int i = 0; i < midpointViews.Length; i++)
            {
                var formerVertexIndex = i;
                var latterVertexIndex = (i + 1) % vertexViews.Length;

                CreateAttachmentBehaviour(ref verticesAttachments, midpointViews[i], formerVertexIndex);
                CreateAttachmentBehaviour(ref verticesAttachments, midpointViews[i], latterVertexIndex);
                CreateAttachmentBehaviour(ref centersAttachments, midpointViews[i], formerVertexIndex);
            }
        }
Esempio n. 26
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //agrega el UIVIew para aplicar el comportamiento de la animacion
            var gravityBehavior = new UIGravityBehavior(square);

            var gravityBehavior2 = new UIGravityBehavior(Balon);

            //limite sobre la collision
            var collisionBehavior = new UICollisionBehavior(square)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };


            var collisionBehavior2 = new UICollisionBehavior(Balon)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };


            //cuando tenga contacto sos los metodo de comenzar y finalizar
            collisionBehavior.BeganBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray;
            };
            collisionBehavior.EndedBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray;
            };

            // Another style of creating the UIDynamicAnimator
            Animator = new UIDynamicAnimator(View)
            {
                gravityBehavior, collisionBehavior
            };

            Animator = new UIDynamicAnimator(View)
            {
                gravityBehavior2, collisionBehavior2
            };

            UIDynamicItemBehavior ball = new UIDynamicItemBehavior(Balon);

            ball.Elasticity = 0.75f;
            Animator.Add(ball);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var collisionBehavior = new UICollisionBehavior(square)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };

            var pushBehavior = new UIPushBehavior(UIPushBehaviorMode.Instantaneous, square)
            {
                Angle     = 0.0f,
                Magnitude = 0.0f
            };

            Animator = new UIDynamicAnimator(View);
            Animator.AddBehaviors(collisionBehavior, pushBehavior);

            redSquare.Center            = new CGPoint(View.Bounds.GetMidX(), View.Bounds.GetMidY());
            redSquare.Layer.AnchorPoint = new CGPoint(0.0f, 0.5f);

            View.AddGestureRecognizer(new UITapGestureRecognizer((gesture) => {
                /*
                 * Tapping will change the angle and magnitude of the impulse.
                 * To visually show the impulse vector on screen, a red line representing
                 * the angle and magnitude of this vector is briefly drawn.
                 */
                CGPoint p      = gesture.LocationInView(View);
                CGPoint o      = new CGPoint(View.Bounds.GetMidX(), View.Bounds.GetMidY());
                float distance = (float)Math.Sqrt((p.X - o.X) * (p.X - o.X) + (p.Y - o.Y) * (p.Y - o.Y));
                float angle    = (float)Math.Atan2(p.Y - o.Y, p.X - o.X);
                distance       = Math.Min(distance, 100.0f);

                redSquare.Bounds    = new CGRect(0.0f, 0.0f, distance, 5.0f);
                redSquare.Transform = CGAffineTransform.MakeRotation(angle);
                redSquare.Alpha     = 1.0f;

                UIView.Animate(1.0f, () => {
                    redSquare.Alpha = 0.0f;
                });

                pushBehavior.Magnitude = distance / 100.0f;
                pushBehavior.Angle     = angle;
                pushBehavior.Active    = true;
            }));
        }
Esempio n. 28
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var Gravedad = new UIGravityBehavior(Imagen1, Imagen2);//Se agrega gravedad a uno de los objectos.
            var Colision = new UICollisionBehavior(Imagen1, Imagen2)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };

            var Rebote = new UIDynamicItemBehavior(Imagen2)
            {
                Elasticity = 1f
            };

            Animador = new UIDynamicAnimator(View);
            Animador.AddBehaviors(Gravedad, Colision, Rebote);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			var collisionBehavior = new UICollisionBehavior (square) {
			    TranslatesReferenceBoundsIntoBoundary = true
			};

			var pushBehavior = new UIPushBehavior (UIPushBehaviorMode.Instantaneous, square) {
				Angle = 0.0f,
				Magnitude = 0.0f
			};

			Animator = new UIDynamicAnimator (View);
			Animator.AddBehaviors (collisionBehavior, pushBehavior);

			redSquare.Center = new PointF (View.Bounds.GetMidX (), View.Bounds.GetMidY ());
			redSquare.Layer.AnchorPoint = new PointF (0.0f, 0.5f);

			View.AddGestureRecognizer (new UITapGestureRecognizer ((gesture) => {
				/*
	    		 Tapping will change the angle and magnitude of the impulse. 
    			 To visually show the impulse vector on screen, a red line representing 
    			 the angle and magnitude of this vector is briefly drawn.
    			 */
				PointF p = gesture.LocationInView (View);
				PointF o = new PointF (View.Bounds.GetMidX (), View.Bounds.GetMidY ());
				float distance = (float)Math.Sqrt ((p.X - o.X) * (p.X - o.X) + (p.Y - o.Y) * (p.Y - o.Y));
				float angle = (float)Math.Atan2 (p.Y - o.Y, p.X - o.X);
				distance = Math.Min (distance, 100.0f);

				redSquare.Bounds = new RectangleF (0.0f, 0.0f, distance, 5.0f);
				redSquare.Transform = CGAffineTransform.MakeRotation (angle);
				redSquare.Alpha = 1.0f;

				UIView.Animate (1.0f, () => {
					redSquare.Alpha = 0.0f;
				});

				pushBehavior.Magnitude = distance / 100.0f;
				pushBehavior.Angle = angle;
				pushBehavior.Active = true;
			}));
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
		
			var gravityBehavior = new UIGravityBehavior (square);

			var collisionBehavior = new UICollisionBehavior (square) {
				TranslatesReferenceBoundsIntoBoundary = true
			};
			collisionBehavior.BeganBoundaryContact += (sender, e) => {
				((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray;
			};
			collisionBehavior.EndedBoundaryContact += (sender, e) => {
				((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray;
			};

			// Another style of creating the UIDynamicAnimator
			Animator = new UIDynamicAnimator (View) { gravityBehavior, collisionBehavior };
		}
Esempio n. 31
0
        private void reset()
        {
            foreach (var subview in Subviews)
            {
                subview.RemoveFromSuperview();
            }

            motionManager?.Dispose();
            gravity?.Dispose();
            spiderAnimator?.Dispose();
            spiderView?.Dispose();

            spiderAnimator = null;
            motionManager  = null;
            gravity        = null;
            spiderView     = null;

            IsVisible = false;
        }
Esempio n. 32
0
		public void applyGravity()
		{
			if (firstTime) {
				firstTime = false;

				TKChartVisualPoint[] points1 = chart.VisualPointsForSeries (chart.Series [0]);
				originalValues = new List<CGPoint> ();
				foreach (TKChartVisualPoint p in points1) {
					originalValues.Add (p.CGPoint);
				}
				TKChartVisualPoint point1 = points1 [4];
				originalLocation = point1.Center;
			}

			animator = new UIDynamicAnimator (chart.PlotView);
			TKChartVisualPoint[] points = chart.VisualPointsForSeries (chart.Series [0]);
			TKChartVisualPoint point = points [4];

			for (int i=0; i<originalValues.Count; i++) {
				TKChartVisualPoint pt = points [i];
				if (pt.Animator != null) {
					pt.Animator.RemoveAllBehaviors();
					pt.Animator = null;
				}
				pt.Center = ((CGPoint)originalValues[i]);
			}

			point.Center = new CGPoint (originalLocation.X, 0);

			UICollisionBehavior collision = new UICollisionBehavior (points);
			collision.TranslatesReferenceBoundsIntoBoundary = true;

			UIGravityBehavior gravity = new UIGravityBehavior (points);
			gravity.GravityDirection = new CGVector (0.0f, 2.0f);

			UIDynamicItemBehavior dynamic = new UIDynamicItemBehavior (points);
			dynamic.Elasticity = 0.5f;

			animator.AddBehavior(dynamic);
			animator.AddBehavior(gravity);
			animator.AddBehavior(collision);
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.White;
            animator = new UIDynamicAnimator(View);
            gravity = new UIGravityBehavior();
            animator.AddBehavior(gravity);

            // Tap to add new item.
            View.AddGestureRecognizer(new UITapGestureRecognizer((gesture) => {
                PointF tapLocation = gesture.LocationInView(View);
                var item = new UIView(new RectangleF(PointF.Empty, sizeInitial)) {
                    BackgroundColor = ColorHelpers.GetRandomColor(),
                    Center = tapLocation,
                };
                items.Enqueue(item);
                View.Add(item);
                gravity.AddItem(item);

                // Clean up old items so things don't get too leaky.
                if (items.Count > 20) {
                    var oldItem = items.Dequeue();
                    oldItem.RemoveFromSuperview();
                    gravity.RemoveItem(oldItem);
                    oldItem.Dispose();
                }
            }));

            // Swipe to change gravity direction.
            View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
                gravity.GravityDirection = new CGVector(1, 0);
            }) { Direction = UISwipeGestureRecognizerDirection.Right, });
            View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
                gravity.GravityDirection = new CGVector(-1, 0);
            }) { Direction = UISwipeGestureRecognizerDirection.Left, });
            View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
                gravity.GravityDirection = new CGVector(0, -1);
            }) { Direction = UISwipeGestureRecognizerDirection.Up, });
            View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
                gravity.GravityDirection = new CGVector(0, 1);
            }) { Direction = UISwipeGestureRecognizerDirection.Down, });
        }
Esempio n. 34
0
        private void preparePhysics()
        {
            spiderView.Center            = new CGPoint(Center.X, -height - spiderImage.Size.Height);
            spiderView.Layer.AnchorPoint = new CGPoint(0.5, 0);

            spiderAnimator = new UIDynamicAnimator(this);

            var spider = new UIDynamicItemBehavior(spiderView);

            spider.Action     = () => SetNeedsDisplay();
            spider.Resistance = spiderResistance;
            spiderAnimator.AddBehavior(spider);

            links = createRope();

            gravity = new UIGravityBehavior(links);
            spiderAnimator.AddBehavior(gravity);

            motionManager?.Dispose();
            motionManager = new CMMotionManager();
            motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, processAccelerometerData);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.White;
            animator = new UIDynamicAnimator(View);

            item = new UIView(new RectangleF(new PointF(50f, 0f), new SizeF(50f, 50f))) {
                BackgroundColor = UIColor.Blue,
            };
            View.Add(item);
            UIGravityBehavior gravity = new UIGravityBehavior(item);
            animator.AddBehavior(gravity);

            // Tap to bring item back.
            View.AddGestureRecognizer(new UITapGestureRecognizer((gesture) => {
                PointF tapLocation = gesture.LocationInView(View);
                // Must remove from gravity first or it will only flash to location
                // then continue animated from where it was.
                gravity.RemoveItem(item);
                item.Center = tapLocation;
                gravity.AddItem(item);
            }));
        }
Esempio n. 36
0
        private void preparePhysics()
        {
            spiderRadius = Math.Sqrt(Math.Pow(spiderImage.Size.Width / 2, 2) + Math.Pow(spiderImage.Size.Height / 2, 2));
            double height = (UIScreen.MainScreen.ApplicationFrame.Size.Width / 2) - 1.5 * spiderRadius;

            spiderAnimator = new UIDynamicAnimator(this);

            var spider = new UIDynamicItemBehavior(spiderView);

            spider.Action         = () => SetNeedsDisplay();
            spider.Resistance     = spiderResistance;
            spider.AllowsRotation = true;
            spiderAnimator.AddBehavior(spider);

            links = createRope(height);

            gravity = new UIGravityBehavior(links);
            spiderAnimator.AddBehavior(gravity);

            motionManager?.Dispose();
            motionManager = new CMMotionManager();
            motionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, processAccelerometerData);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			var screenBounds = UIScreen.MainScreen.Bounds;
			var length = Math.Floor (0.1 * Math.Max (screenBounds.Width, screenBounds.Height));

			itemView = new UIView (new CGRect (0.0, 0.0, length, Math.Floor (length / ItemAspectRatio))) {
				AutoresizingMask = UIViewAutoresizing.None,
				BackgroundColor = UIColor.Red
			};

			var panGestureRecognizer = new UIPanGestureRecognizer (Pan);
			itemView.AddGestureRecognizer (panGestureRecognizer);
			View.AddSubview (itemView);

			var longPressGestureRecognizer = new UILongPressGestureRecognizer (LongPress);
			View.AddGestureRecognizer (longPressGestureRecognizer);

			animator = new UIDynamicAnimator (View);
			stickyBehavior = new StickyCornersBehavior (itemView, (float)length * 0.5f);
			animator.AddBehavior (stickyBehavior);
		}
Esempio n. 38
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var gravityBehavior = new UIGravityBehavior(square);

            var collisionBehavior = new UICollisionBehavior(square)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };

            collisionBehavior.BeganBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray;
            };
            collisionBehavior.EndedBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray;
            };

            var squareCenterPoint = new PointF(square.Center.X, square.Center.Y - 100);

            var attachmentBehavior = new UIAttachmentBehavior(square, squareCenterPoint)
            {
                Frequency = 1.0f,
                Damping   = 0.1f
            };

            redSquare.Center  = attachmentBehavior.AnchorPoint;
            blueSquare.Center = new PointF(50.0f, 50.0f);

            Animator = new UIDynamicAnimator(View);
            Animator.AddBehaviors(attachmentBehavior, gravityBehavior, collisionBehavior);

            View.AddGestureRecognizer(new UIPanGestureRecognizer((gesture) => {
                attachmentBehavior.AnchorPoint = gesture.LocationInView(View);
                redSquare.Center = attachmentBehavior.AnchorPoint;
            }));
        }
Esempio n. 39
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var gravityBehavior = new UIGravityBehavior(square);

            var collisionBehavior = new UICollisionBehavior(square)
            {
                TranslatesReferenceBoundsIntoBoundary = true
            };

            collisionBehavior.BeganBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray;
            };
            collisionBehavior.EndedBoundaryContact += (sender, e) => {
                ((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray;
            };

            // Another style of creating the UIDynamicAnimator
            Animator = new UIDynamicAnimator(View)
            {
                gravityBehavior, collisionBehavior
            };
        }
        private void ViewDidLoadForImageMode() 
        {
            View.BackgroundColor = UIColor.Black;
            View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;

            this.BlackBackdrop = new UIView (new RectangleF (View.Bounds.X, View.Bounds.Y, -512, -512));
            this.BlackBackdrop.BackgroundColor = UIColor.Black;
            this.BlackBackdrop.Alpha = 0;
            View.AddSubview (BlackBackdrop);

            ScrollView = new UIScrollView (View.Bounds);
            ScrollView.WeakDelegate = this;
            ScrollView.ZoomScale = 1.0f;
            ScrollView.MaximumZoomScale = 8.0f;
            ScrollView.ScrollEnabled = false;
            ScrollView.IsAccessibilityElement = true;
            //self.scrollView.accessibilityLabel = self.accessibilityLabel; // NEED TO IMPLEMENT THIS
            ScrollView.AccessibilityHint = AccessibilityHintZoomedOut ();
            View.AddSubview (ScrollView);

            RectangleF referenceFrameInWindow = ImageInfo.ReferenceView.ConvertRectToView (ImageInfo.ReferenceRect, null);
            RectangleF referenceFrameInMyView = View.ConvertRectFromView (referenceFrameInWindow, null);

            ImageView = new UIImageView (referenceFrameInMyView);
            ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
            ImageView.UserInteractionEnabled = true;
            ImageView.IsAccessibilityElement = false;
            ImageView.ClipsToBounds = true;
            ImageView.Layer.AllowsEdgeAntialiasing = true;

            SetupImageModeGestureRecognizers ();

            ProgressContainer = new UIView (new RectangleF (0, 0, 128.0f, 128.0f));
            View.AddSubview (ProgressContainer);

            ProgressView = new UIProgressView (UIProgressViewStyle.Default);
            ProgressView.Progress = 0;
            ProgressView.TintColor = UIColor.White;
            ProgressView.TrackTintColor = UIColor.DarkGray;

            RectangleF progressFrame = ProgressView.Frame;
            ProgressView.Frame = progressFrame;
            ProgressView.Center = new PointF (64.0f, 64.0f);
            ProgressView.Alpha = 0;
            ProgressContainer.AddSubview (ProgressView);
            Spinner = new UIActivityIndicatorView (UIActivityIndicatorViewStyle.WhiteLarge);
            Spinner.Center = new PointF (64.0f, 64.0f);
            Spinner.StartAnimating();
            ProgressContainer.AddSubview (Spinner);
            ProgressContainer.Alpha = 0;

            Animator = new UIDynamicAnimator (ScrollView);

            if (Image != null) {
                UpdateInterfaceWithImage (Image);
            }
        }
        protected void DynamicAnimatorDidPause(UIDynamicAnimator animator)
        {
            this.Animator.RemoveAllBehaviors();

            _collision = null;
            _topView   = null;
            _push      = null;
            _gravity   = null;
            _composite = null;
            _animator  = null;

            this.SlidingViewController.TopViewController.View.UserInteractionEnabled = true;

            UIViewController topController = this.SlidingViewController.GetViewControllerForKey(ECSlidingViewController.ECTransitionContextTopViewControllerKey);
            if ((_panningRight && _positiveLeftToRight) || (!_panningRight && !_positiveLeftToRight))
            {
                topController.View.Frame = this.SlidingViewController.GetFinalFrameForViewController(topController);
                this.SlidingViewController.FinishInteractiveTransition();
            }
            else if ((_panningRight && !_positiveLeftToRight) || (!_panningRight && _positiveLeftToRight))
            {
                topController.View.Frame = this.SlidingViewController.GetInitialFrameForViewController(topController);
                this.SlidingViewController.CancelInteractiveTransition();
            }

            this.SlidingViewController.CompleteTransition(true);
        }
Esempio n. 42
0
		public override void TouchesEnded (NSSet touches, UIEvent evt)
		{
			base.TouchesEnded (touches, evt);

			if (selectedPoint == null) {
				return;
			}

			UISnapBehavior snap = new UISnapBehavior(selectedPoint, originalPosition);
			snap.Damping = 0.2f;

			UIPushBehavior push = new UIPushBehavior(new IUIDynamicItem[] { selectedPoint }, UIPushBehaviorMode.Instantaneous);
			push.PushDirection = new CGVector(0.0f, -1.0f);
			push.Magnitude = 0.001f;

			UIDynamicAnimator animator = new UIDynamicAnimator();
			animator.AddBehavior(snap);
			animator.AddBehavior(push);

			selectedPoint.Animator = animator;
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AddSnapArea();

            animator = new UIDynamicAnimator(View);

            // offsets used to position image relative to touch point while being dragged
            float dx = 0;
            float dy = 0;

            using (var image = UIImage.FromFile("monkey.png")) {
                imageView = new UIImageView(image)
                {
                    Frame = new RectangleF(new PointF(0, 0), image.Size)
                };
                imageView.UserInteractionEnabled = true;
                View.AddSubview(imageView);
            }

            panGesture = new UIPanGestureRecognizer((pg) => {
                if ((pg.State == UIGestureRecognizerState.Began || pg.State == UIGestureRecognizerState.Changed) && (pg.NumberOfTouches == 1))
                {
                    // remove any previosuly applied snap behavior to avoid a flicker that will occur if both the gesture and physics are operating on the view simultaneously
                    if (snap != null)
                    {
                        animator.RemoveBehavior(snap);
                    }

                    var p0 = pg.LocationInView(View);

                    if (dx == 0)
                    {
                        dx = p0.X - imageView.Center.X;
                    }

                    if (dy == 0)
                    {
                        dy = p0.Y - imageView.Center.Y;
                    }


                    // this is where the offsets are applied so that the location of the image follows the point where the image is touched as it is dragged,
                    // otherwise the center of the image would snap to the touch point at the start of the pan gesture
                    var p1 = new PointF(p0.X - dx, p0.Y - dy);

                    imageView.Center = p1;
                }
                else if (pg.State == UIGestureRecognizerState.Ended)
                {
                    // reset offsets when dragging ends so that they will be recalculated for next touch and drag that occurs
                    dx = 0;
                    dy = 0;

                    SnapImageIntoPlace(pg.LocationInView(View));
                }
            });

            imageView.AddGestureRecognizer(panGesture);

            View.BackgroundColor = UIColor.White;
        }
Esempio n. 44
0
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();
            var verifica = new LAContext();
            var autoriza = await verifica.EvaluatePolicyAsync
                               (LAPolicy.DeviceOwnerAuthenticationWithBiometrics,
                               "Autenticación FaceID");

            if (autoriza.Item1)
            {
                var voz = new AVSpeechUtterance("Está usted autorizado en la Aplicación, sea Bienvenido");
                voz.Voice = AVSpeechSynthesisVoice.FromLanguage("es-MX");
                habla.SpeakUtterance(voz);
                lblEstatus.Text = "Autorizado";
            }
            else
            {
                lblEstatus.Text = "No Autorizado";

                var Gravedad = new UIGravityBehavior(Imagen, btnConfirmar, btnGuardar, lblEstatus);
                var Colision = new UICollisionBehavior(Imagen, btnConfirmar, btnGuardar, lblEstatus)
                {
                    TranslatesReferenceBoundsIntoBoundary = false
                };
                var Rebote = new UIDynamicItemBehavior(btnConfirmar)
                {
                    Elasticity = 1f
                };
                Animador = new UIDynamicAnimator(View);
                Animador.AddBehaviors(Gravedad, Colision, Rebote);
                System.Threading.Thread.CurrentThread.Abort();
            }
            var Firma = new SignaturePadView(View.Frame)
            {
                StrokeWidth     = 3f,
                StrokeColor     = UIColor.Black,
                BackgroundColor = UIColor.White,
            };

            Firma.Frame                     = new CGRect(10, 500, 350, 200);
            Firma.Layer.BorderWidth         = 1f;
            Firma.SignaturePrompt.TextColor = UIColor.Blue;
            Firma.Caption.TextColor         = UIColor.White;
            Firma.Caption.Text              = "Firmar en esta zona";
            View.AddSubview(Firma);

            btnConfirmar.TouchUpInside += delegate
            {
                Imagen.Image = Firma.GetImage();
            };
            btnGuardar.TouchUpInside += delegate
            {
                var imagenfirma = Firma.GetImage();
                try
                {
                    imagenfirma.SaveToPhotosAlbum(delegate
                                                  (UIImage imagen, NSError error)
                                                  { });
                    lblEstatus.Text = "Guardado en biblioteca";
                }
                catch (Exception ex)
                {
                    lblEstatus.Text = ex.Message;
                }
            };
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			Animator = new UIDynamicAnimator (View);
			Animator.AddBehavior (new UIGravityBehavior (square));
		}
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     Animator = new UIDynamicAnimator(View);
     Animator.AddBehavior(new UIGravityBehavior(square));
 }
Esempio n. 47
0
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            base.TouchesEnded (touches, evt);

            if (selectedPoint == null) {
                return;
            }

            UITouch touch = (UITouch)touches.AnyObject;
            CGPoint touchPoint = touch.LocationInView(chart.PlotView);
            CGPoint delta = new CGPoint(originalLocation.X, originalLocation.Y - touchPoint.Y);

            UISnapBehavior snap = new UISnapBehavior(selectedPoint, originalPosition);
            snap.Damping = 0.2f;

            UIPushBehavior push = new UIPushBehavior(new IUIDynamicItem[] { selectedPoint }, UIPushBehaviorMode.Instantaneous);
            push.PushDirection = new CGVector(0.0f, delta.Y > 0 ? -1.0f : -1.0f);
            push.Magnitude = 0.001f;

            UIDynamicAnimator animator = new UIDynamicAnimator();
            animator.AddBehavior(snap);
            animator.AddBehavior(push);

            selectedPoint.Animator = animator;
        }
Esempio n. 48
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear (animated);

            TKChartVisualPoint[] points = chart.VisualPointsForSeries (chart.Series [0]);
            originalValues = new List<CGPoint> ();
            foreach (TKChartVisualPoint p in points) {
                originalValues.Add (p.CGPoint);
            }
            TKChartVisualPoint point = points[4];

            UISnapBehavior snap = new UISnapBehavior (point, point.Center);
            snap.Damping = 0.2f;

            UIPushBehavior push = new UIPushBehavior (new IUIDynamicItem[] { point }, UIPushBehaviorMode.Instantaneous);
            push.PushDirection = new CGVector (0.0f, -1.0f);
            push.Magnitude = 0.003f;

            UIDynamicAnimator animator = new UIDynamicAnimator();
            animator.AddBehavior(snap);
            animator.AddBehavior(push);

            point.Animator = animator;
        }