永远不会调用自定义视图上的UIPanGestureRecognizer

时间:2015-01-21 09:36:31

标签: ios iphone xamarin uigesturerecognizer

我正在使用Xamarin iOS并且我有一个自定义视图(继承自UIView),我尝试添加一个简单的UIPanGestureRecognizer,请参阅:< / p>

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

但是“Pan”从未在控制台中显示:/

同样,我有一个自定义视图。

编辑: 当我移动我的代码时:

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); 致UIVIewController这适用://///为什么???

我应该使用UIGestureDelegate做什么吗?!

1 个答案:

答案 0 :(得分:0)

你还必须添加以下内容。

目标C:

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

根据Xamarin语法设置此内容。

也试试这个。

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

请参阅以下链接,了解Xamarin中的更新Pangesture。

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