swift - 模拟器和电话不显示相同的匹配几何效果结果
问题描述
我有一个非常简单的例子,我想让一个正方形更大。在模拟器中一切看起来都很好,但是当我在手机上运行它时,正方形变得透明。
内容视图
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@Namespace var animation
@State var isBig:Bool = false
var body: some View {
ZStack {
Color(.red)
if(!isBig){
RectangleViewSmoll(isBig:$isBig, animation: animation)
}
if(isBig){
RectangleViewBig(isBig:$isBig,animation: animation)
}
}
.ignoresSafeArea()
}
}
小矩形
struct RectangleViewSmoll: View {
@Binding var isBig:Bool
var animation:Namespace.ID
var body: some View {
Rectangle()
.matchedGeometryEffect(id: "rectangle", in: animation)
.frame(width: 50, height: 50)
.onTapGesture {
withAnimation(.easeIn(duration: 2)){
isBig.toggle()
}
}
}
}
大长方形
struct RectangleViewBig: View {
@Binding var isBig:Bool
var animation:Namespace.ID
var body: some View {
Rectangle()
.matchedGeometryEffect(id: "rectangle", in: animation)
.frame(width: 500, height: 500)
.onTapGesture {
withAnimation(.easeIn(duration: 2)){
isBig.toggle()
}
}
}
}
解决方案
问题在于动画线,尝试这样可以解决您的问题:
Rectangle()
.matchedGeometryEffect(id: "rectangle", in: animation)
.frame(width: 500, height: 500)
.onTapGesture {
isBig.toggle()
}
.animation(.easeIn(duration: 2))
推荐阅读
- gulp - 如何使用 BrowseSync 修复“Cannot GET/”错误?
- azure - Azure 通过 webhook 启动/停止 VM
- docker - 删除我所有的本地 docker 图像和容器不起作用
- c++ - 是否有通用标准方法将浮点数存储在 std::set 和/或 std::unordered_set 中?
- python-3.x - 在“编译”期间捕获 Python 中的导入错误和名称错误
- javascript - 完整日历 - 未实现时间动态输入
- c# - 读取 MySQL JSON 数据类型并将其转换为 List
在 C# 中 - css - 某些字体粗细不会在具有不同 @font-face 负载的移动设备上加载
- docker - 如何通过 JAAS 配置 kafka env 变量 kubernetes
- encryption - 如何解密数据并确定加密算法