Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Touches events are not fired on Mac

$
0
0

Hi,
I need to get coordinates of user touch on Mac. I created a custom renderer deriving from ViewRenderer. I created a class that derives from NSClickRecognizer and override TouchesBegan, TouchesCancelled, TouchesMoved and TouchesEnded methods but none of them are fired when user press the view. When I add a recognizer with action in constructor, the action is raised but I am not able to get coordinates.
The code looks like this

public class ViewGesturesRenderer : ViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);
            var tapGestureRecognizer = new TapGestureRecognizer();
            if (e.OldElement == null)
            {
                this.AddGestureRecognizer(tapGestureRecognizer);
                this.AddGestureRecognizer(new TapGestureRecognizer(() =>
                {
                    //this fires correctly
                }));
            }
        }

        public class TapGestureRecognizer : NSClickGestureRecognizer
        {
            public TapGestureRecognizer(Action action) : base(action) { }
            public TapGestureRecognizer() { }
            public override void TouchesBegan(NSEvent touchEvent)
            {
                //not fired
                base.TouchesBegan(touchEvent);
            }
            public override void TouchesCancelled(NSEvent touchEvent)
            {
                //not fired
                base.TouchesCancelled(touchEvent);
            }
            public override void TouchesMoved(NSEvent touchEvent)
            {
                //not fired
                base.TouchesMoved(touchEvent);
            }
            public override void TouchesEnded(NSEvent touchEvent)
            {
                //not fired
                base.TouchesEnded(touchEvent);
            }
        }
    }

Thanks,
Martin


Viewing all articles
Browse latest Browse all 77050

Trending Articles