Example #1
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;
            }));
        }
		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();

            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();

            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;
            }));
        }
 public override void PrepareLayout()
 {
     base.PrepareLayout ();
     if (this.dynamicAnimator.Behaviors.Count () == 0) {
         var s = this.CollectionViewContentSize;
         var rec = new RectangleF (0, 0, s.Width, s.Height);
         foreach (var item in base.LayoutAttributesForElementsInRect(rec)) {
             UIAttachmentBehavior behaviour = new UIAttachmentBehavior (item, item.Center);
             behaviour.Length = 0.0f;
             behaviour.Damping = 0.8f;
             behaviour.Frequency = 1.0f;
             dynamicAnimator.AddBehavior (behaviour);
         }
     }
 }
Example #7
0
 public override void PrepareLayout()
 {
     base.PrepareLayout();
     if (this.dynamicAnimator.Behaviors.Count() == 0)
     {
         var s   = this.CollectionViewContentSize;
         var rec = new RectangleF(0, 0, s.Width, s.Height);
         foreach (var item in base.LayoutAttributesForElementsInRect(rec))
         {
             UIAttachmentBehavior behaviour = new UIAttachmentBehavior(item, item.Center);
             behaviour.Length    = 0.0f;
             behaviour.Damping   = 0.8f;
             behaviour.Frequency = 1.0f;
             dynamicAnimator.AddBehavior(behaviour);
         }
     }
 }
Example #8
0
        private UIView[] createRope()
        {
            var    chain    = new List <UIView>();
            UIView lastLink = null;

            for (int i = 0; i < chainLength; i++)
            {
                var chainLink = createChainLink(i * chainLinkHeight, lastLink);
                chain.Add(chainLink);
                lastLink = chainLink;
            }

            var spiderAttachment = new UIAttachmentBehavior(spiderView, UIOffset.Zero, lastLink, UIOffset.Zero);

            spiderAttachment.Length = spiderAttachmentLength;
            spiderAnimator.AddBehavior(spiderAttachment);

            chain.Add(spiderView);

            return(chain.ToArray());
        }
        private UIView[] createRope(double length)
        {
            double chainLinkHeight = length / chainLength;
            var    chain           = new List <UIView>();
            UIView lastLink        = null;

            for (int i = 0; i < chainLength; i++)
            {
                var chainLink = createChainLink(i, chainLinkHeight, lastLink);
                chain.Add(chainLink);
                lastLink = chainLink;
            }

            spiderView.Center       = new CGPoint(Center.X, -length + spiderImage.Size.Height / 2);
            spiderAttachment        = new UIAttachmentBehavior(lastLink, UIOffset.Zero, spiderView, new UIOffset(0, -spiderImage.Size.Height / 2));
            spiderAttachment.Length = 0;
            spiderAnimator.AddBehavior(spiderAttachment);

            chain.Add(spiderView);

            return(chain.ToArray());
        }
Example #10
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;
            }));
        }
 // Dynamic Image Dragging Methods
 private void StartImageDragging(PointF panGestureLocationInView, UIOffset translationOffset)
 {
     ImageDragStartingPoint = panGestureLocationInView;
     ImageDragOffsetFromActualTranslation = translationOffset;
     PointF anchor = ImageDragStartingPoint;
     PointF imageCenter = ImageView.Center;
     UIOffset offset = new UIOffset (panGestureLocationInView.X - imageCenter.X, panGestureLocationInView.Y - imageCenter.Y);
     ImageDragOffsetFromImageCenter = offset;
     AttachmentBehavior = new UIAttachmentBehavior (ImageView, offset, anchor);
     Animator.AddBehavior (AttachmentBehavior);
     UIDynamicItemBehavior modifier = new UIDynamicItemBehavior(new IUIDynamicItem[] { ImageView });
     modifier.AngularResistance = AppropriateAngularResistanceForView (ImageView);
     Animator.AddBehavior (modifier);
 }