【发布时间】:2020-01-14 15:42:54
【问题描述】:
有没有办法检查某个元素内是否有一个手势触摸,比如Frame?
我在屏幕上添加了PanGestureRecognizer。在我的屏幕上,我有两个Frame,其中包含两个Image。我想要的是,当我在屏幕上移动手指时,当我的手指停在其中一个帧上时,我会注意到。我知道如何获取我的手指坐标 (e.TotalX; e.TotalY;),我的想法是检查它们是否在帧的范围内,但我不知道如何。
有什么建议吗?
代码
public MainPage()
{
InitializeComponent();
var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += PanUpdated;
mainLayout.GestureRecognizers.Add(panGesture);
dog = new Frame
{
BorderColor = Color.Blue,
Padding = 4,
Content = new Image
{
Source = ImageSource.FromResource("AccessibilityImagesSound.Immagini.dog.png"),
Aspect = Aspect.Fill,
},
};
AutomationProperties.SetIsInAccessibleTree(dog, true);
AutomationProperties.SetName(dog, "dog");
AbsoluteLayout.SetLayoutBounds(dog, new Rectangle(0.2, 0.5, 0.30, 0.30));
AbsoluteLayout.SetLayoutFlags(dog, AbsoluteLayoutFlags.All);
mainLayout.Children.Add(dog);
cat = new Frame
{
BorderColor = Color.Blue,
Padding = 4,
Content = new Image
{
Source = ImageSource.FromResource("AccessibilityImagesSound.Immagini.cat.png"),
Aspect = Aspect.Fill,
},
};
AutomationProperties.SetIsInAccessibleTree(cat, true);
AutomationProperties.SetName(cat, "cat");
AbsoluteLayout.SetLayoutBounds(cat, new Rectangle(0.8, 0.5, 0.30, 0.30));
AbsoluteLayout.SetLayoutFlags(cat, AbsoluteLayoutFlags.All);
mainLayout.Children.Add(cat);
}
private void PanUpdated(object sender, PanUpdatedEventArgs e)
{
switch (e.StatusType)
{
case GestureStatus.Started:
break;
case GestureStatus.Running:
//Here I think I have to check E.TotalX and e.TotalY
break;
case GestureStatus.Completed:
case GestureStatus.Canceled:
break;
}
}
【问题讨论】:
标签: xamarin.forms touch coordinates uipangesturerecognizer