简体   繁体   中英

UIPanGestureRecognizer on a Custom View never called

I m using Xamarin for iOS and I have a custom view (inherit from UIView ), And I try to add a simple UIPanGestureRecognizer , see this:

UIPanGestureRecognizer panGesture = new UIPanGestureRecognizer (() => Console.WriteLine ("Pan");
this.AddGestureRecognizer(panGesture);

But "Pan" never shown in the console :/

Again, I have a custom view.

Edit: When I move my code:

UIView myView = new UIView (new RectangleF(0,0,200,200));
myView.BackgroundColor = UIColor.Red;
myView.UserInteractionEnabled = true;    

var recognizer = new UIPanGestureRecognizer ((g) => {
                    Console.WriteLine ("Panning detected");
                    Console.WriteLine ("Gesture recognizer state: {0}", g.State);
                });

myView.AddGestureRecognizer (recognizer);

AddSubview (myView); To the UIVIewController this works :///// why???

Should I do something with the UIGestureDelegate ?!

also you have to add below things.

Objective C:

[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];

Set this thing according to Xamarin syntax.

Also try this.

var panGesture = new UIPanGestureRecognizer (() => Console.WriteLine ("Pan");
this.view.AddGestureRecognizer(panGesture);

See below link for Updated Pangesture in Xamarin.

http://www.slideshare.net/Xamarin/whats-new-in-xamarinios-miguel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM