当前位置:网站首页>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 边栏推荐
- Pandonia spirit voxedit creation competition
- 营销与销售文件管理以及工作流程解决方案
- 传惠普/戴尔/微软/亚马逊考虑将部分硬件生产线转到大陆以外
- 执行上下文与词法环境
- New features of ES6
- Marketing and sales document management and workflow solutions
- QT signal and slot connection (loose coupling)
- BGP routing black hole and anti ring
- Principle and application of one click login of local number (glory Collection Edition)
- 深度可分离卷积(DepthwiseSeparableConvolution):Depthwise卷积与Pointwise卷积
猜你喜欢

81. (cesium home) cesium modifies the gray background (default blue)

Summary of message queue knowledge points

Shell综合应用案例,归档文件

解决IBGP的水平分割和BGP选路原则

Easycvr device management list page, paging data does not display problem repair

BGP -- Border Gateway Protocol

Houdini 笔记2

执行上下文与词法环境

Houdini finds the midpoint and connects the points to form a line

BUU刷题记-网鼎杯专栏2
随机推荐
英国德国相继推出5G商用服务,华为成幕后功臣
Robin Lee was "poured cold water" enthusiasm! Baidu allied with Huawei Kirin to release "Honghu" chip
[experiment sharing] CCIE BGP routing black hole experiment]
Gartner released the latest market guide for Chinese AI start-ups, and Hongji cyclone was once again rated as a representative enterprise
一层节点训练5个坐标的超简单神经网络代码
Leetcode's question brushing -- List summary
BGP -- Border Gateway Protocol
What are the key technologies of digital factory
Can the training software test be employed
The lawyer team of the US Department of justice asked the judge to refuse to accept Huawei's lawsuit
单核A7玩转人脸识别,恩智浦“跨界处理器”又玩出新花样!
hello 你好吗
81.(cesium之家)cesium修改灰色背景(默认蓝色)
Correct the classpath of your application so that it contains compatible versions of the classes com
BGP--边界网关协议
How to check whether the pytorch you are using is a GPU version
解决IBGP的水平分割和BGP选路原则
Chat software project development 2
tkinter使用wpf控件
New features of ES6