delphiiOS和平移手势 – 距离始终为零

我有这个(现在工作)的代码基于我拾起各地的位:

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

我怀疑你在各个地方拾起的代码实际上是有效的:

TGestureInfo的文档明确指出

[…]距离仅适用于缩放和双指轻敲手势 (TInteractiveGesture = igZoom或igTwoFingerTap)。 […]

这意味着您将不得不跟踪onGesture之前的手指注册位置。 然后你可以做一些关于EventInfo.LocationEventInfo.Location的区别。 当然,如果gfBegin不在GestureEvent.Flags ,这只会GestureEvent.Flags因为对于以前的位置你不会有一个有效的值,但是你已经知道了。

此外,你可能会看看EventInfo.InertiaVector “当你抬起你的手指时,东西会继续移动”。 但是这完全是可选的。

另外,如果你正在处理一个手势(不pipe是交互式还是标准手势),你应该把Handled设置为True 。 这样,您不会冒险尝试处理该手势的另一个组件。 但说实话,我不确定FireMonkey是否也是如此。 用Vcl,它是。 将FMX.Types.TInteractiveGestures的文档与Vcl.Controls.TInteractiveGestureOption进行比较 。 比对不起更安全。

嗨,我一直在开发一个滚动条自定义fmx列表框。 我发现泛交互式手势事件在窗口和ios之间的处理方式是不同的。 在ios中TInteractiveGestureFlag.gfInertia标志未设置为惯性事件gfBegin和gfEnd标志的缺失表示正在发生惯性摇摄事件。

fvscroll是一个标准的滚动条组件。

scmfx,scmfy是私有类variablesTopItem设置我的自定义列表框的topitem ItemHeight是列表框项目的高度

 procedure TFCListBox.FlickScroll(const Ev: TGestureEventInfo); var N:TDateTime; dy,dx,dz,rad:single; begin if TInteractiveGestureFlag.gfBegin in ev.flags then begin PanStartTime := N; PanStartEv := Ev; scrollstart := fvscroll.value; rad := DegToRad(RotationAngle); scmfx := sin(rad); scmfy := cos(rad); end; if (TInteractiveGestureFlag.gfInertia in ev.Flags) or (ev.Flags = []) then begin dy := (Ev.Location.Y - PanStartEv.Location.y) *scmfy; dx := (Ev.Location.X - PanStartEv.Location.X) *scmfx; dz := dx - dy; fvscroll.Value := scrollstart + dz; end; if TInteractiveGestureFlag.gfEnd in ev.Flags then begin TopItem := Round(fvScroll.Value/ItemHeight);} end; end; 

我希望这是有帮助的