Capturing x and y custom touch, iOS Xamarin Forms

I am using Xamarin Forms (Xamarin Studio Community) to write an iOS app. I just need to fix the coordinates of the custom touch and release to the button.

I searched all over Google and I found answers that just didn't work. They were either Android, Swift, XCode, or WAY too many for practical use.

The closest I've seen are answers that say "There is currently no way to do this in Xamarin Forms." This seems absurd to me because it seems like one of the simplest and most fundamental things a programmer will need.

All I need is to grab x, y where the user touches and releases. Here are my handlers ready to go.

    thisHereButton.TouchDown += (object sender, System.EventArgs e) =>
    {
        //pressed
        touchX = [x];
        touchY=[y];
    };
     thisHereButton.TouchUpInside += (object sender, System.EventArgs e) =>
    {
        //released
        releaseX = [x];
        releaseY=[y];
    }; 

      

What is it. If someone could provide a simple, practical answer, that would be great!

EDIT: More research is coming with a generosity, in the hopes that someone can help.

I followed the guidelines in the comments and after some analysis determined that this is the most appropriate piece of code.

private bool touchStartedInside;
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);
            // get the touch
            UITouch touch = touches.AnyObject as UITouch;
            if (touch != null)
            {
                //==== IMAGE TOUCH
                if (backdrop.Frame.Contains(touch.LocationInView(View)))
                {
                    //TouchStatus.Text = "Touches Moved";
                }

                //==== IMAGE DRAG
                // check to see if the touch started in the drag me image
                if (touchStartedInside)
                {
                    // move the shape
                    float offsetX = (float)(touch.PreviousLocationInView(View).X - touch.LocationInView(View).X);
                    float offsetY = (float)(touch.PreviousLocationInView(View).Y - touch.LocationInView(View).Y);
                    txt_sizeValText.Text = "" + offsetY;
                    //DragImage.Frame = new RectangleF(new PointF(DragImage.Frame.X - offsetX, DragImage.Frame.Y - offsetY), DragImage.Frame.Size);
                }
         }
        }  

      

This is taken directly from their example. Right there in the code, it gives me what I'm looking for, as well as the "offset" bonus I really need at the end. So I have this void in my code and the code is still compiling, so there are no errors.

The only thing I can't figure out is how to use this emptiness. What do you call it? If I need to use a different handler than the ones in my original post, that's fine. Whatever you tell me about how to make this work ...

+3


source to share


1 answer


You don't need to call the TouchesMoved () method. It is automatically called when the Objective C runtime calls it (this is an override of the method that will be called). It's basically a custom event handler. You can get offsets already and you can raise your own events inside this method to change your button. This has already been done.



+3


source







All Articles