CopyPastor

Detecting plagiarism made easy.

Score: 0.8091106414794922; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2025-04-20
by Markus Buchanan

Original Post

Original - Posted on 2022-03-20
by HunterLion



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I had a similar issue and I finally found a solution that worked for me, try wrapping the view in a ZStack and utilizing a .clipped modifier like the below code.
``` struct ContentView: View { @State var animation: Bool = false var body: some View { VStack {
// This is the Button Button(action: { withAnimation(.spring(dampingFraction: 1, blendDuration: 0.5)) { animation.toggle() } }) { Image(systemName: "star.fill") .resizable() .frame(width: 100, height: 100) .foregroundColor(.accentColor) } ZStack{ // This condition sends up the View if animation { SecondView() .transition(.move(edge: .bottom)) } }.clipped() } .padding() } } ```
Your code is fine (besides the fact that you need a `VStack` wrapping the text and the button), you only need to tell SwiftUI to use the transition by wrapping the command inside `withAnimation()`.
Here's what you simply need to do in ContentView (look at the Button):
``` @ObservedObject var viewModel = ViewModel() var body: some View { VStack { if self.viewModel.model.show { Text("Showing") .padding() } else { Text("Not Showing") .padding() .transition(.asymmetric(insertion: .scale, removal: .opacity)) } Button { withAnimation { // This is what you need to trigger the transition self.viewModel.show() } } label: { Text("Tap to change") } } .animation(.easeIn, value: self.viewModel.show)
} ```

        
Present in both answers; Present only in the new answer; Present only in the old answer;