问题描述
我正在尝试检测应用程序中的缩放操作(捏),但由于某种原因,事件未始终被调用(有时是,有时不是)。
我创建了一个示例应用程序,可以很容易地复制它:
<Page
x:Class="Manipulate.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="Red" ManipulationMode="Scale" ManipulationDelta="Grid_ManipulationDelta" ManipulationStarted="Grid_ManipulationStarted"/>
</Page>
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace Manipulate
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Grid_ManipulationStarted(object sender,ManipulationStartedRoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine($"Started {e.}");
}
private void Grid_ManipulationDelta(object sender,ManipulationDelTaroutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine($"Delta {e.Delta.Scale}");
}
}
}
在我的实际应用程序中,我试图实现缩放以放大自定义相机的实现(受https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/CameraManualControls启发),但是由于ManipulationStarted
和{{ 1}}在每个捏手势上均被一致调用。
我在多个Surface设备(Surface Book,Surface Go,Surface Pro 4)上看到了这一点。
解决方法
请检查此Touch interactions文档。
捏捏手势两个或更多个手指触摸屏幕,并向近移。换句话说,您需要合拢两个按下的手指。我已经使用模拟器进行了测试,并且效果很好。这是您可以参考的sample code。
std::vector<int> arrPtrKS {113,220,235};
for (int i = 0; i < arrPtrKS.size(); i++)
{
int oddDigitcount = 0;
int originalValue = arrPtrKS[i];
while (arrPtrKS[i] > 0)
{
if (arrPtrKS[i] % 2)
{
oddDigitcount++;
}
arrPtrKS[i] /= 10;
}
std::cout << originalValue << " has " << oddDigitcount << " odd digits" << std::endl;
}
更新
从@Cosmin派生似乎我在使用20226.1000的Windows版本中存在问题。此问题已解决。请检查博客here。