Custom gesture recognizer

AlvaroRivoirAlvaroRivoir USMember ✭✭✭

I'm trying to create a custom NSGestureRecognizer, but the property NSGestureRecognizer.State is read-only. Any idea how to change the state?

Best Answers

Answers

  • DarioOrgazDarioOrgaz USMember ✭✭

    Hi,

    You should create a class that inherit from UIGestureRecognizer and after override all the methods that you want.

  • AlvaroRivoirAlvaroRivoir USMember ✭✭✭

    It's actually NSGestureRecognizer, because it is for Mac.

    I already inherited the class, but it doesn't allow setting State

            private class NSManipulationRecognizer : NSGestureRecognizer
            {
                public NSManipulationRecognizer(Action action)
                    : base(action)
                {
                    ShouldRecognizeSimultaneously = (a, b) => true;
                }
                public override void TouchesBegan(NSEvent touchEvent)
                {
                    base.TouchesBegan(touchEvent);
                    //State = NSGestureRecognizerState.Began;
                }
    
                public override void TouchesEnded(NSEvent touchEvent)
                {
                    base.TouchesEnded(touchEvent);
                    //State = NSGestureRecognizerState.Ended;
                }
    
                public override void TouchesCancelled(NSEvent touchEvent)
                {
                    base.TouchesCancelled(touchEvent);
                    //State = NSGestureRecognizerState.Cancelled;
                }
            }
    
  • AlvaroRivoirAlvaroRivoir USMember ✭✭✭

    The workaround worked fine. Thanks. I look forward to seeing this fixed in version 15.6.

Sign In or Register to comment.