swift - 影响模态背景的 SwiftUI 动画
问题描述
我在 ListView() 中有一张带有简单动画的表格:
.overlay(
ZStack{
Group {
Circle()
.fill(Color.blue)
.opacity(animatingButton ? 0.2 : 0)
.frame(width: 68, height: 68, alignment: .center)
.scaleEffect(animatingButton ? 1 : 0)
Circle()
.fill(Color.blue)
.opacity(animatingButton ? 0.15 : 0)
.frame(width: 88, height: 88, alignment: .center)
.scaleEffect(animatingButton ? 1 : 0)
}
.animation(Animation.easeInOut(duration: 2.0).repeatForever(autoreverses: true))
导致圆圈的大小不断扩大和缩小。
在模态中,我有一个 TabView 并设置了一个背景图像,如下所示:
TabView(selection: $VM.modalSelectedPage){
ListView()
.background(Image(VM.backgroundImage)
.resizable()
.aspectRatio(contentMode: .fill)
.edgesIgnoringSafeArea(.all))
....
}
问题是,如果我注释掉,从模态底部向上拖动时,此动画会导致不需要的行为
.animation(Animation.easeInOut(duration: 2.0).repeatForever(autoreverses: true))
问题消失了。
我试过添加
.animation(nil)
到 .background 不起作用。
在这里您可以看到问题:https ://imgur.com/E8S01kd
在这里你可以看到它在没有动画的情况下工作:https ://imgur.com/fjI0Aiz
复制错误的简单代码
模态视图:
import SwiftUI
struct ModalView: View {
var body: some View {
HStack{
Text("")
.animation(.default) // Comment out to fix issue
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.green)
.edgesIgnoringSafeArea(.all)
}
}
内容视图:
import SwiftUI
struct ContentView: View {
@State private var showingModal = false
var body: some View {
Button(action: {
self.showingModal.toggle()
}, label: {
Text("Open Modal")
})
.sheet(isPresented: $showingModal, content: {
ModalView()
})
}
}
解决方案
推荐阅读
- html - 如何调整svg的大小?
- c++ - 如何将二维数组(矩阵)传递给函数?
- regex - 编写一些正则表达式的其他可能方式
- azure-cosmosdb - gremlin - 使用不同的 where 子句将列表与单个列表分开
- sql-server - 如何在 SQL Server 报表生成器中向堆积条形图添加自定义指标线
- c# - Entity Framework Core 错误地查询关系
- php - 未经身份验证尝试访问后发送消息
- php - codeigniter- 带有图像和 pdf 上传的表单
- python - 为什么我在 offset_adjusted_list 变量上出现语法错误?
- c# - 如何在面板中移动图片框?