我有一个带有游戏板的应用程序,可以使用 mr.gestures 拾取和移动瓷砖,效果很好。
我的游戏板是一个MR.Gestures.AbsoluteLayout
,这就是我捕捉平移手势的地方。
如果我将该游戏板作为孩子添加到另一个游戏板,MR.Gestures.AbsoluteLayout
那么手势似乎被父母阻止并且不再起作用。
有没有办法将手势传递给孩子或以某种方式忽略父母的手势?
我有一个带有游戏板的应用程序,可以使用 mr.gestures 拾取和移动瓷砖,效果很好。
我的游戏板是一个MR.Gestures.AbsoluteLayout
,这就是我捕捉平移手势的地方。
如果我将该游戏板作为孩子添加到另一个游戏板,MR.Gestures.AbsoluteLayout
那么手势似乎被父母阻止并且不再起作用。
有没有办法将手势传递给孩子或以某种方式忽略父母的手势?
Is there a way to pass gestures though to children or ignore gestures on a parent in some way?
For me this problem appeared only on Android.. The answer is Yes:
When parent receives gesture event it must check if finger x,y is within specific childs views. If yes, parent just ignores the gesture.
Regarding the code, ill just past one event handler to get the idea. In my case i have 2 childs (like and bookmark) over a parent frame:
//-------------------------------------------------------------------
private void OnTapped_MainFrame(object sender, TapEventArgs e)
//-------------------------------------------------------------------
{
//Get parent screen abs pos in pixels
//We are using native code get absolute screen position
var ptFrame = DependencyService.Get<INiftyHelpers>().GetViewAbsolutePosition((View)sender);
//Gets childs (hotspots) screen abs position in pixels
var ptFav = DependencyService.Get<INiftyHelpers>().GetViewAbsolutePosition((View)hsFav);
var ptLike = DependencyService.Get<INiftyHelpers>().GetViewAbsolutePosition((View)hsLike);
//Gets childs (hotspots) rectangles, everything in pixels using screen density
var rectFav = new Rectangle(ptFav, new Size(hsFav.Width * AppHelper.DisplayDensity, hsFav.Height * AppHelper.DisplayDensity));
var rectLike = new Rectangle(ptLike, new Size(hsLike.Width * AppHelper.DisplayDensity, hsLike.Height * AppHelper.DisplayDensity));
//Convert the finger XY to screen pos in pixels
var ptTouch = new Point(ptFrame.X + e.Center.X * AppHelper.DisplayDensity, ptFrame.Y + e.Center.Y * AppHelper.DisplayDensity); //absolute relative to screen
//check if withing childs
if (rectFav.Contains(ptTouch) || rectLike.Contains(ptTouch))
return; //Ignore input and let childs process their gestures!
//Process input
//..
}