Delphi XE5 for android 图片缩放和拖动处理
首先,需要分辨手势的类型。
 有两种类型的手势:
     一是标准手势(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;
 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号