Swiftui 旋转3D效果对文本具有不希望的效果
这个问题与其他动画问题有何不同:我没有看到任何涉及反向文本的文章。请参阅下文: 以下是导致这种情况的代码:Swiftui 旋转3D效果对文本具有不希望的效果,swiftui,Swiftui,这个问题与其他动画问题有何不同:我没有看到任何涉及反向文本的文章。请参阅下文: 以下是导致这种情况的代码: .rotation3DEffect( .init(degrees: isTapped ? 180 : 0), axis: (x: 0.0, y: 1.0, z: 0.0), anchor: .center, anchorZ: 20.0, perspective: 1.
.rotation3DEffect(
.init(degrees: isTapped ? 180 : 0),
axis: (x: 0.0, y: 1.0, z: 0.0),
anchor: .center,
anchorZ: 20.0,
perspective: 1.0
)
以下是我试图解决的问题::
import SwiftUI
struct ContentView: View {
let grid = [GridItem(.fixed(100), spacing: 5, alignment: .center),
GridItem(.fixed(100), spacing: 5, alignment: .center),
GridItem(.fixed(100), spacing: 5, alignment: .center)]
var body: some View {
VStack {
LazyVGrid(columns: grid, content: {
ForEach(Example.example, id: \.name) { ex in
AnimatedView(data: ex)
}
})
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct Example {
let name: String
let translation: String
static let example =
[Example(name: "First", translation: "Second"),
Example(name: "Third", translation: "Fourth"),
Example(name: "Fifth", translation: "Sixth"),
Example(name: "Seventh", translation: "Eigth"),
Example(name: "Ninth", translation: "Tenth"),
Example(name: "Eleventh", translation: "Twelth")
]
}
struct AnimatedView: View {
@State private var isTapped = false
let data: Example
var body: some View {
Button(action: {self.isTapped.toggle()}) {
Text(isTapped ? data.name : data.translation)
.padding()
.foregroundColor(.white)
.frame(width: 100)
.background(isTapped ? Color.blue : .black)
.cornerRadius(8)
}.rotation3DEffect(
.init(degrees: isTapped ? 180 : 0),
axis: (x: 0.0, y: 1.0, z: 0.0),
anchor: .center,
anchorZ: 0,
perspective: 0
)
.animation(.linear)
}
}
struct AnimatedView:View{
@状态私有变量isTapped=false
let数据:示例
var body:一些观点{
按钮(操作:{self.istaped.toggle()}){
文本(isTapped?data.name:data.translation)
.padding()
.foregroundColor(.白色)
.框架(宽度:100)
.background(isTapped?Color.blue:.黑色)
.转弯半径(8)
.rotation3DEffect(//你会添加一些可复制的代码吗?@Yodagama是的,抱歉,我刚刚添加了。可以将其直接插入XcodeWorth,考虑通过单独的组件制作,如中。我们可以使用动画数据来获得更好的旋转效果,如真卡!如果可能,希望看到一个简短的示例或一个好的参考