Actually, this is really a problem, because the UIScrollView events " are " TouchesMoved (even if they distribute the first few).
So, I just came up with an approach to get events directly from UIWindow . This is probably not the best approach in terms of application structure, but in some user situation (which was exactly what I needed) in order.
(Examples are given in MonoTouch C #).
UIWindow ( , UIWindow MyWindow - ( MvvmCross), appDelegate - google/stack):
public class MyWindow : UIWindow
{
public MyWindow(RectangleF bounds) : base(bounds)
{
}
public override void SendEvent(UIEvent evt)
{
if (evt.Type == UIEventType.Touches) {
var el = (UITouch)evt.AllTouches.AnyObject;
if (el.Phase == UITouchPhase.Began)
{
if(OnTouchBegan != null)
OnTouchBegan(el.View, new TouchCommandArgs(evt.AllTouches, evt));
}
if (el.Phase == UITouchPhase.Moved)
{
if(OnTouchMoved != null)
OnTouchMoved(el.View, new TouchCommandArgs(evt.AllTouches, evt));
}
if (el.Phase == UITouchPhase.Ended)
{
if(OnTouchEnd != null)
OnTouchEnd(el.View, new TouchCommandArgs(evt.AllTouches, evt));
}
if (el.Phase == UITouchPhase.Cancelled)
{
if(OnTouchCancel != null)
OnTouchCancel(el.View, new TouchCommandArgs(evt.AllTouches, evt));
}
} else
MvxTrace.Trace (evt.Type == null ? "-" : evt.ToString ());
base.SendEvent(evt);
}
public event TouchCommand OnTouchBegan;
public event TouchCommand OnTouchEnd;
public event TouchCommand OnTouchCancel;
public event TouchCommand OnTouchMoved;
}
public class TouchCommandArgs : EventArgs
{
public NSSet Touches { get; set; }
public UIEvent Evt { get; set; }
public TouchCommandArgs(NSSet touches, UIEvent evt)
{
Touches = touches;
Evt = evt;
}
}
:
var window = (MyWindow) UIApplication.SharedApplication.KeyWindow;
window.OnTouchBegan += view_OnTouchBegan;
window.OnTouchMoved += view_OnTouchMoved;
window.OnTouchCancel += view_OnTouchCancel;
window.OnTouchEnd += view_OnTouchEnd;
( -):
void view_OnTouchBegan(object sender, TouchCommandArgs args)
{
}
( : UIScrollView), , , , , , ( , "Handled" ).