Android实例-GestureManager手势支持放大缩小左右移动上下移动
2023-09-14 08:57:11 时间
相关资料:
https://download.csdn.net/download/zhujianqiangqq/62483987 代码包下载
实例代表:
Unit1.fmx
界面中有三个图片,太大不方便上传,请从CSDN上下载代码包。
Unit1.pas
1 unit Unit1; 2 3 interface 4 5 uses 6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 8 FMX.Controls.Presentation, FMX.StdCtrls, FMX.Gestures, FMX.TabControl, 9 FMX.Objects 10 ,System.Generics.Collections 11 ,System.Math, FMX.Layouts 12 ; 13 14 type 15 TForm1 = class(TForm) 16 GestureManager1: TGestureManager; 17 Image1: TImage; 18 Rectangle1: TRectangle; 19 Layout1: TLayout; 20 Image2: TImage; 21 Layout2: TLayout; 22 Image3: TImage; 23 Image4: TImage; 24 Label1: TLabel; 25 procedure FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo; 26 var Handled: Boolean); 27 procedure Image2Click(Sender: TObject); 28 private 29 { Private declarations } 30 FLastPosition : TPointF; 31 FLastDIstance : integer ; 32 FOriginalWidth : Single ; 33 LImage: TImage; 34 public 35 { Public declarations } 36 end; 37 38 var 39 Form1: TForm1; 40 41 implementation 42 43 {$R *.fmx} 44 45 procedure TForm1.FormGesture(Sender: TObject; 46 const EventInfo: TGestureEventInfo; var Handled: Boolean); 47 var 48 LObj: IControl; 49 LImageCenter: TPointF; 50 Tan :single; 51 A,B :single; 52 begin 53 inherited; 54 55 Label1.Text := IntToStr(EventInfo.GestureID); 56 if EventInfo.GestureID = igiZoom then//放大缩小手势 57 begin 58 LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location)); 59 if LObj is TImage then 60 begin 61 if (not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags)) and 62 (not(TInteractiveGestureFlag.gfEnd in EventInfo.Flags)) then 63 begin 64 LImage := TImage(LObj.GetObject); 65 LImageCenter := LImage.Position.Point + PointF(LImage.Width / 2, LImage.Height / 2); 66 if LImage.Width<FOriginalWidth then 67 begin 68 LImage.Width := LImage.Width + (power(2,(EventInfo.Distance - FLastDistance)/10)-1)*10; // 控制u图片缩小速度和大小,滑的越大变化越小,后面变化无限小 69 LImage.Height := LImage.Height + (power(2,(EventInfo.Distance - FLastDistance)/10)-1)*10;// 70 end 71 else 72 begin 73 LImage.Width := LImage.Width + 2*(EventInfo.Distance - FLastDistance); 74 LImage.Height := LImage.Height + 2*(EventInfo.Distance - FLastDistance); 75 end; 76 LImage.Position.X := LImageCenter.X - LImage.Width / 2; 77 LImage.Position.Y := LImageCenter.Y - LImage.Height / 2; 78 end; 79 FLastDistance := EventInfo.Distance; 80 end; 81 Exit; 82 end; 83 84 //平移 85 if EventInfo.GestureID = igiPan then 86 begin 87 LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location)); 88 if LObj is TImage then 89 begin 90 if not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags) then 91 begin 92 LImage := TImage(LObj.GetObject); 93 if (LImage <> nil) then 94 begin 95 LImage.Position.X := LImage.Position.X + (EventInfo.Location.X - FLastPosition.X); 96 LImage.Position.Y := LImage.Position.Y + (EventInfo.Location.Y - FLastPosition.Y); 97 end; 98 end; 99 FLastPosition := EventInfo.Location; 100 Exit; 101 end; 102 end; 103 end; 104 105 procedure TForm1.Image2Click(Sender: TObject); 106 var 107 oImage: TImage; 108 begin 109 if Sender is TImage then 110 begin 111 oImage := (Sender as TImage); 112 Image1.Bitmap.Assign(oImage.Bitmap); 113 end; 114 end; 115 116 end.
相关文章
- [Android Pro] 利用tcpdump和wireshark对android网络请求进行分析
- [Android 新特性] Android 4.3 Top 5新功能
- Android实例-LocationSensor位置传感器(XE8+小米2)
- Android实例-录音与回放(播放MP3)(XE8+小米2)
- Android实例-TRectangle加载图片(XE8+小米2)
- Android实例-处理隐藏输入法后不再显示问题(XE8+小米2)
- Android实例-TTabControl的使用(XE8+小米2)
- Android Studio 优秀插件汇总(转载)
- 【COCOS2D-X(2.X) 游戏开发系列之二】COCOS2DX最新2.X版本跨平台整合NDK+XCODE,XCODE编写&编译代码,ANDROID导入打包运行即可!
- Android中流式布局和热门标签
- [Android] IntentService使用详解和实例介绍
- Android开发学习笔记(十六)开关按钮
- Android自定义TextView根据控件高度和宽度,解决字体适配问题
- 【Android笔记55】Android之如何使用ViewPager2实现自动轮播图的效果
- Android报错提示:Failed to resolve: com.android.support.constraint:constraint-layout:1.1.3
- Android 9.0 系统framework层禁止访问应用信息页功能实现
- 【Android 逆向】函数拦截实例 ( 函数拦截流程 | ① 定位动态库及函数位置 )
- Android的Bitmap和BitmapDrawable类解析-android学习之旅(六十)
- 导入Eclipse工程 到 Android Studio
- Android12安装报错:Targeting S+ (version 31 and above) requires that an explicit value for android:export
- Android在layout xml中使用include
- 使用Android Studio build tensorflow/examples/android——直接用android studio即可
- 用Android Studio进行NDK编程入门实例
- Android 自定义的验证码输入框(无光标),android版本10暂时不支持自定义粘贴
- Android Studio 4.2.2 Kotlin的import kotlinx.android.synthetic.main.(layout的xml名).view.*
- android开发,开发环境(Android Studio)安装
- Android Studio第一个NDK程序
- Android内核开发:理解和掌握repo工具
- Android OTA升级(1):编译升级全包