【发布时间】:2020-05-25 11:10:20
【问题描述】:
在我的应用中,我有这样的看法:
import SwiftUI
let defaults = UserDefaults.standard
struct ContentView: View {
@State var haveSeenIntroduction: Bool = defaults.bool(forKey: "haveSeenIntroduction")
var body: some View {
ZStack {
if self.haveSeenIntroduction {
DefaultView()
} else {
IntroductionView(haveSeenIntroduction: $haveSeenIntroduction)
}
}.transition(.scale)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
在“IntroductionView”中我有这样的按钮:
Button(action: {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
let defaults = UserDefaults.standard
defaults.set(true, forKey: "haveSeenIntroduction")
withAnimation {
self.haveSeenIntroduction = true
}
})
当我按下按钮时,在父视图中使用 ZStack 时,过渡看起来有问题(前一个视图“跳起来”并且看起来很糟糕),而使用 Group 过渡时根本不会发生。如何解决此问题并实现这两个视图之间的过渡而不会出现滞后、跳跃等问题?
【问题讨论】:
标签: ios swift swiftui transition