Swiftui 剪贴画过渡不';我什么也不做
我试图在屏幕上显示一个带有自定义圆形过渡的矩形。但是,无论我做什么,矩形都将被剪裁,但没有动画。它只是扑通一声出现在屏幕上 我的代码:Swiftui 剪贴画过渡不';我什么也不做,swiftui,Swiftui,我试图在屏幕上显示一个带有自定义圆形过渡的矩形。但是,无论我做什么,矩形都将被剪裁,但没有动画。它只是扑通一声出现在屏幕上 我的代码: import SwiftUI let screenWidth = UIScreen.main.bounds.size.width let screenHeight = UIScreen.main.bounds.size.height struct ContentView: View { @State var rectangleShown
import SwiftUI
let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height
struct ContentView: View {
@State var rectangleShown = false
var body: some View {
ZStack {
Button(action: {
rectangleShown = true
}, label: {
Text("Show Rectangle")
}) .zIndex(0)
if rectangleShown {
Rectangle().frame(width: screenWidth*0.9, height: screenHeight*0.9)
.transition(.iris)
.zIndex(1)
}
}
}
}
自定义转换的代码(我在网上找到的,但对我来说似乎没问题):
及
及
以及
withAnimation(.default) {
rectangleShown = true
}
在上述所有情况下,根本没有任何运动。我还尝试了自定义不透明度转换,也没有动画。另一方面,如果我只做一个简单的(.slide)转换,它就会工作。有人能看看出了什么问题吗?谢谢 当在按钮操作中添加带有动画的
块时,它似乎在Xcode 12.3/iOS 14.3中工作:带有动画{rectangleShowed=true}
。你使用什么环境?我也有同样的问题,同样的代码在iOS 13中工作得很好…当在按钮操作中添加带动画的块时,它似乎在Xcode 12.3/iOS 14.3中工作:带动画的{rectangleShowed=true}
。你使用什么环境?我有同样的问题,同样的代码在iOS 13中运行良好。。。
Rectangle().frame(width: screenWidth*0.9, height: screenHeight*0.9)
.transition(AnyTransition.iris.animation(Animation.easeInOut(duration: 2)))
.zIndex(1)
Rectangle().frame(width: screenWidth*0.9, height: screenHeight*0.9)
.transition(AnyTransition.iris)
.animation(Animation.easeInOut(duration: 2))
.zIndex(1)
Rectangle().frame(width: screenWidth*0.9, height: screenHeight*0.9)
.animation(Animation.easeInOut(duration: 2))
.transition(AnyTransition.iris)
.zIndex(1)
withAnimation(.default) {
rectangleShown = true
}