当前位置:网站首页>SwiftUI使用MatchedGeometryEffect快速同步不同继承层级中视图的位置和尺寸
SwiftUI使用MatchedGeometryEffect快速同步不同继承层级中视图的位置和尺寸
2022-08-08 00:46:00 【大熊猫侯佩】

功能需求
在SwiftUI中,我们有时希望将两个或多个视图放置在相同位置上,而不管它们在哪个视图继承层级中。
我们曾在 SwiftUI任意继承层级中视图被裁剪显示不全的解决方案 博文中讨论过一种解决方案。
不过该方案有两个小问题:
- 代码比较复杂
- 视图被多次刷新后才会“稳定”(即会被多次重建,然后重建结果被丢弃)

如上图所示,使用本文介绍的新方法,我们在拖拽滚动视图时,视图一直保持“稳定”状态,即不会被反复多次重建。
该方法可以用来同步SwiftUI中任何视图之间的大小和位置。
So,废话少叙,Let’s do it!
功能分析
1. 旧方法的"缺陷"
看过之前博文代码的童鞋都知道,我们是用PreferenceKey机制来实现的。
不过,正如之前提到的那样,这种方法有两个问题。
首先是它实现起来比较复杂,需要额外添加多个辅
边栏推荐
- 解决:ERROR: Cannot uninstall ‘certifi‘. It is a distutils installed project and thus we cannot accurat
- Is it safe to buy stocks with great wisdom?Will the funds be transferred?
- sci 顶刊中的 3D 密度函数图
- 本古里安大学|基于深度强化学习的稠密神经网络多目标剪枝
- 手机股票开户是安全的吗,靠谱吗?
- Antdv+Asp.net WebApi Development of Student Information Management System (1)
- Shell脚本中常用命令复习
- 华为|通过拍卖实现长期网络资源分配的多智能体强化学习:V2X 应用
- 陈强教授《机器学习及R应用》课程 第五章作业
- I want to open an account for stock trading, is it safe to open an account?
猜你喜欢

SAP 的MPN功能
![[LeetCode周赛复盘] 第 305 场周赛20220807](/img/9e/a09e0ebec985341f972ccc6b15aa53.png)
[LeetCode周赛复盘] 第 305 场周赛20220807

Introduction to c language --- custom types: structures, enumerations, unions

IDEA 工具类及其余类方法测试方式

Stack SQL injection, rounding

Distributed agreement of Lease mechanism

Good news | Hongshi data has obtained CMMI level 3 certification!Welcome to the self-developed unified operation and maintenance monitoring platform!

带你刷(牛客网)C语言百题(第五天)

阿包的夜宵

5、基于EasyExcel的导入导出
随机推荐
LeetCode weeks checking] "305th week 20220807
继承关系下构造方法的访问特点
Eureka Basics
weblogic后台通过配置文件修改jdbc数据源密码
PyTorch 源码解读之 torch.utils.data:解析数据处理全流程(非常好,一篇足够)
使用大智慧炒股,资金能保证安全吗?
MySQL之索引
Antdv+Asp.net WebApi Development of Student Information Management System (1)
Embedded sharing collection 31-serial port
最小公倍数三种方法(附代码)
Two queues implement a stack
Eureka基础知识
深度解读 Vite 的依赖扫描?
torch.utils.data of PyTorch source code interpretation: the whole process of parsing data processing (very good, one article is enough)
DataNode Disk Detection Service
SAP 的MPN功能
永远不停歇
pycharm connect to remote server
有关原码,反码,补码那些事
Rdkit常用命令/参数设置