菜鸟教程小白 发表于 2022-12-12 13:01:55

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


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

<pre><code>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 &lt;&gt; 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 &lt; 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 &lt; layoutMapsContent.Width)
            or
            (H &lt; 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
;
</code></pre>

<p>我的缩放工作得很好(虽然不是在模拟器中,而是在 iOS iPhone 上),但是平移根本不起作用。在模拟器中平移时,我可以看到 eventdisance 始终为 0。我在 TImage 上启用了平移 + 缩放功能。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我怀疑你在不同地方找到的代码是否真的有效:</p>

<p><a href="http://docwiki.embarcadero.com/Libraries/XE3/en/FMX.Types.TGestureEventInfo" rel="noreferrer noopener nofollow">documentation on TGestureInfo</a>明确指出</p>

<blockquote>
<p>[...] Distance is <strong>only set for the zoom and two finger tap gestures</strong> (TInteractiveGesture = igZoom or igTwoFingerTap). [...]</p>
</blockquote>

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

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

<p>此外,如果您正在处理手势(无论是交互式手势还是标准手势),您应该将 <code>Handled</code> 设置为 <code>True</code>。这样,您就不会冒另一个组件尝试处理该手势的风险。但老实说,我不确定 FireMonkey 是否也是这种情况。使用 Vcl,它是。比较 <a href="http://docwiki.embarcadero.com/Libraries/XE4/en/FMX.Types.TInteractiveGestures" rel="noreferrer noopener nofollow">FMX.Types.TInteractiveGestures</a> 的文档与 <a href="http://docwiki.embarcadero.com/Libraries/XE4/en/Vcl.Controls.TInteractiveGestureOption" rel="noreferrer noopener nofollow">Vcl.Controls.TInteractiveGestureOption</a> .安全总比后悔好。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Delphi iOS 和平移手势 - 距离始终为零,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/17907730/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/17907730/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Delphi iOS 和平移手势 - 距离始终为零