私はさまざまな場所で拾ったビットに基づいて、この(現在動作している)コードを持っています:
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 でパン + ズーム ジェスチャを有効にしました。