• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:01:55 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有这个 (现在工作) 代码,基于我在各个地方找到的位:

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 上启用了平移 + 缩放功能。



Best Answer-推荐答案


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

documentation on TGestureInfo明确指出

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

这意味着您必须跟踪在上一次调用 onGesture 时手指注册的位置。然后,您可以针对当时的 EventInfo.Location 和现在的 EventInfo.Location 的区别做一些事情。当然,这只有在 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap