我需要将TouchEvent添加到UIScrollView中,但是当我触摸ScrollView时似乎永远不会调用方法TouchesBegan
。我从here找到了解决方案。还必须添加singleTapGesture。但是,由于某种原因,我不能这样做。这是唯一的解决方案吗?
答案 0 :(得分:0)
您可以在任何视图上添加手势识别器,这样做:
myView.AddGestureRecognizer(new UITapGestureRecognizer(() =>
{
//Do Something
}));
答案 1 :(得分:0)
您可以自定义继承自UIScrollView
的子类。并覆盖方法TouchesBegan
TouchesBegan
和TouchesMoved
public class MyScrollerView: UIScrollView
{
public MyScrollerView()
{
}
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
this.NextResponder.TouchesBegan(touches, evt);
}
public override void TouchesMoved(NSSet touches, UIEvent evt)
{
this.NextResponder.TouchesMoved(touches, evt);
}
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
this.NextResponder.TouchesEnded(touches, evt);
}
}
在xxx.cs中
var myScrollView = new MyScrollerView();
myScrollView.UserInteractionEnabled = true;
myScrollView.DelaysContentTouches = false; // it is important
//. . .
现在您可以在TouchesBegan
TouchesBegan
TouchesMoved
和ViewController
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
// do some you want
}