I need to add TouchEvent into a UIScrollView but it seems the method TouchesBegan
will never been called when I touch the ScrollView.I find a solution from here.And I have to add a singleTapGesture .However,I can't do that for some reason.Is it the only solution?
Asked
Active
Viewed 240 times
0

Akai Rika
- 59
- 6
2 Answers
0
You can add a gesture recognizer on any view, doing this:
myView.AddGestureRecognizer(new UITapGestureRecognizer(() =>
{
//Do Something
}));

El0din
- 3,208
- 3
- 20
- 31
-
Thanks for your answer.As I said that I couldn't add a TapGesture – Akai Rika Oct 12 '18 at 00:43
0
You can customize a subclass that inherits from UIScrollView
.And override the method TouchesBegan
TouchesBegan
and 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);
}
}
in xxx.cs
var myScrollView = new MyScrollerView();
myScrollView.UserInteractionEnabled = true;
myScrollView.DelaysContentTouches = false; // it is important
//. . .
And now you can call the method TouchesBegan
TouchesBegan
and TouchesMoved
in the ViewController
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
// do some you want
}

Lucas Zhang
- 18,630
- 3
- 12
- 22