ios - Delphi iOS 和平移手势 - 距离始终为零

标签 ios delphi firemonkey pan

我有这个(现在可以使用)代码,它基于我在不同地方收集的位:

procedure TFormMain.imgMapsGesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
  LObj: IControl;
  LImage: TImage;
  W: Single;
  H: Single;
begin
  LImage := nil;
  LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location));
  if (LObj is TImage) and (LObj.Visible) then
    begin
      LImage := TImage(LObj.GetObject);
      if (LImage <> imgMaps) then
        LImage := nil
      ;
    end
  ;
  if LImage = nil then
    Exit
  ;
  if LImage.Bitmap = nil then
    Exit
  ;
  case EventInfo.GestureID of
    igiZoom:
      begin
        if (EventInfo.Distance < 1) then
          Exit
        ;
        if
          (not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags))
          and
          (not(TInteractiveGestureFlag.gfEnd in EventInfo.Flags))
        then
          begin
            W := LImage.Width + 2 * ((EventInfo.Distance - FLastDistanceZoom) / 3);
            H := LImage.Height + 2 * ((EventInfo.Distance - FLastDistanceZoom) / 3);
            if
              (W < layoutMapsContent.Width)
            or
              (H < layoutMapsContent.Height)
            then
              begin
                W := layoutMapsContent.Width;
                H := layoutMapsContent.Height;
              end
            ;
            LImage.Width := W;
            LImage.Height := H;
            FLastDistanceZoom := EventInfo.Distance;
          end
        ;
      end
    ;
igiPan:
  begin
    if
      (not(TInteractiveGestureFlag.gfEnd in EventInfo.Flags))
    then
      begin
        if (not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags)) then
          begin
            LImage.Position.X := LImage.Position.X + (EventInfo.Location.X - FMapsLastPositionPan.X);
            LImage.Position.Y := LImage.Position.Y + (EventInfo.Location.Y - FMapsLastPositionPan.Y);
          end
        ;
        FMapsLastPositionPan.X := EventInfo.Location.X;
        FMapsLastPositionPan.Y := EventInfo.Location.Y;
      end
    ;
  end
;

我的缩放效果相当好(虽然不是在模拟器中,但在 iOS iPhone 上),但是平移根本不起作用。在模拟器中平移时,我可以看到 eventdisance 始终为 0。我在 TImage 上启用了平移 + 缩放功能。

最佳答案

我怀疑你在不同地方找到的代码是否真的有效:

documentation on TGestureInfo明确指出

[...] Distance is only set for the zoom and two finger tap gestures (TInteractiveGesture = igZoom or igTwoFingerTap). [...]

这意味着您将必须跟踪手指在上一次 onGesture 调用中注册的位置。然后,您可以针对 EventInfo.Location then 和 EventInfo.Location now 的区别做一些事情。当然,只有当 gfBegin 不在 GestureEvent.Flags 中时,这才会起作用,因为您没有先前位置的有效值,但您已经知道了。

此外,您可能会查看 EventInfo.InertiaVector,了解“当您抬起手指时,物体会继续移动一点”。但这完全是可选的。

此外,如果您正在处理手势(无论是交互式手势还是标准手势),您应该将 Handled 设置为 True。这样,您就不会冒另一个组件尝试处理手势的风险。但老实说,我不确定 FireMonkey 是否也是这种情况。使用 Vcl,它是。比较 FMX.Types.TInteractiveGestures 的文档与 Vcl.Controls.TInteractiveGestureOption .安全总比遗憾好。

关于ios - Delphi iOS 和平移手势 - 距离始终为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17907730/

相关文章:

ios - 使用 editActions 和 PerformSegue 编辑 UITableView 行?

ios - 从 MKTileOverlayPath 获取 MKMapRect

delphi - 为什么 D2010 调试器会使某些事情变慢?

delphi - Delphi中单独线程中运行WebService的问题

delphi - 在 Delphi 中如何获得给定 MIME 类型的标准文件扩展名?

delphi - 在应用程序中为相机制作预览窗口

安卓10,唤醒

ios - 从服务器获取数据后,直到单击屏幕后, TableView 才会显示数据

delphi - FMX Direct 2D 问题

ios - 我如何播放 [UInt8] 音频流?