当前位置:网站首页>Swiftui 4's new function of real-time access to click location.Ontapgeture {location in} (tutorial with source code)
Swiftui 4's new function of real-time access to click location.Ontapgeture {location in} (tutorial with source code)
2022-07-26 20:46:00 【Knowledge fatness】
SwiftUI 4 Added support for tracking click locations , It is a kind of CGPoint type , It can provide us with the exact location of the click . By default , The location provided is from the local coordinate system of the view .

Let's create an example , We will create an orange circle , The circle will be animated to the click position .
struct TapGestureLocationExample: View {
@State private var pos = CGPoint(x: 100, y: 100)
var body: some View {
VStack {
Circle()
.fill(Color.orange.gradient)
.frame(width: 50)
.position(pos)
Spacer()
}
.background(Color.gray.opacity(0.3))
.onTapGesture { location in
withAnimation(Animation.easeOut(duration: 2)) {
pos = location
}
}
}
}
We can use the following statement to specify the coordinate system :
.onTapGesture(coordinateSpace: .global)
Let's update our code :
struct TapGestureLocationExample: View {
@State 边栏推荐
- The sandbox cooperates with artist Alec monopoly
- [wechat applet] zero basics | applet syntax
- NVIDIA canvas first experience~
- Tinui development history
- 实验5 OSPF综合实验
- Establishment of APP automation testing framework (VIII) -- establishment of ATX server2 multi device cluster environment
- 81. (cesium home) cesium modifies the gray background (default blue)
- BGP--边界网关协议
- APP自动化测试框架搭建(八)--ATX Server2多设备集群环境搭建
- ST表、带权并查集
猜你喜欢

Gartner发布最新《中国AI初创企业市场指南》,弘玑Cyclone再次被评为代表性企业

Principle and application of one click login of local number (glory Collection Edition)
![[interview brush 101] dynamic planning 1](/img/aa/cf9326d0a4363e96f4e2f1c6079c13.png)
[interview brush 101] dynamic planning 1

Tinui development history

QT信号与槽连接(松耦合)

【微信小程序】零基础学 | 小程序语法

易基因|宏病毒组测序技术介绍
![[experiment sharing] CCIE BGP routing black hole experiment]](/img/c8/7ccb879ad7c739d3573637fd14f4e1.png)
[experiment sharing] CCIE BGP routing black hole experiment]

营销与销售文件管理以及工作流程解决方案

Houdini notes 2
随机推荐
Gartner released the latest market guide for Chinese AI start-ups, and Hongji cyclone was once again rated as a representative enterprise
Correct the classpath of your application so that it contains compatible versions of the classes com
【【实验分享】CCIE—BGP路由黑洞实验】
Fitting the new direction of curriculum standards, ape guidance, creating a characteristic new concept content system
PSPICE 仿真石英晶体振荡电路
arpspoof 安装和使用
Solve the horizontal segmentation of iBGP and BGP routing principles
Marketing and sales document management and workflow solutions
Summary of message queue knowledge points
如何查看你使用的pytorch是否为GPU版本
Do employees have to compensate the company for losses when they resign? The 34 year old captain resigned and was claimed 10.66 million yuan by the company
消息队列——引入的问题:重复消费&顺序消费&分布式事务
Hello, how are you
confd+etcd实现高可用自动发现
[Delphi] different platform descriptions of borderstyles of FMX form
Group convolution
Principle and application of one click login of local number (glory Collection Edition)
Gartner发布最新《中国AI初创企业市场指南》,弘玑Cyclone再次被评为代表性企业
Leetcode-300 longest increasing subsequence
[experiment sharing] CCIE BGP routing black hole experiment]