Delphi XE5 for android 图片缩放和拖动处理

本文介绍了在不同操作系统上实现触摸手势的方法,包括标准手势和互动手势的区别及应用。通过实例展示了如何利用互动手势实现图片的放大和平移操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先,需要分辨手势的类型。

有两种类型的手势:
一是标准手势(Standard Gestures):
在Windows,android上,标准手势都是用一个手指。
在Mac OS X and iOS上,是两个手指。
手势完成后(用户拿起手指)后,OnGesture事件被触发(如果一个标准的手势进行识别)。

 


二是互动手势(interactive Gestures):。
多点触摸手势(igZoom,igRotate,等等),它们相当于Windows系统的手势,在Mac OS X,的iOS和Android上同样支持。
每一次移动手指在触摸表面上,一个OnGesture事件被触发。

四个标准手势向上,向下,向左和向右等同于交互式滑动手势。

 

 

 

 


第三, 建议编程只使用互动手势(interactive Gestures)就足够满足一般需要,并且尽量不要与标准手势混合使用。

放大:
var
LObj: IControl;
image: TImage;

begin

LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location));
if LObj is TImage then
begin
if not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags) then
begin
image := TImage(LObj.GetObject);
image.Width := image.Width + (EventInfo.Distance - FLastDIstance)/2;
image.Height := image.Height + (EventInfo.Distance - FLastDIstance)/2;
image.Position.X := image.Position.X - (EventInfo.Distance - FLastDIstance)/2;
image.Position.Y := image.Position.Y - (EventInfo.Distance - FLastDIstance)/2;
end;
end;
FLastDIstance := EventInfo.Distance;

end;

平移:

begin
LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location));
if LObj is TImage then
begin
if not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags) then
begin
image := TImage(LObj.GetObject);
//Set the X coordinate.
image.Position.X := image.Position.X + (EventInfo.Location.X - FLastPosition.X);
if image.Position.X < 0 then
image.Position.X := 0;
if image.Position.X > (Panel1.Width - image.Width) then
image.Position.X := Panel1.Width - image.Width;

//Set the Y coordinate.
image.Position.Y := image.Position.Y + (EventInfo.Location.Y - FLastPosition.Y);
if image.Position.Y < 0 then
image.Position.Y := 0;
if image.Position.Y > (Panel1.Height - image.Height) then
image.Position.Y := Panel1.Height - image.Height;
end;

FLastPosition := EventInfo.Location;
end;

转载于:https://www.cnblogs.com/happyhills/p/3559357.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值