Subspecies do not hide / show during transition

I wrote a function to flip. During the animation, I want to hide one view and show another.

This does not work. But if I try to move this view after the transition is complete, it will show me my desired result.

Below is the code I wrote.

func tapped() {
    if (showingBack) {
        UIView.transitionWithView(self.contentView!, duration: 1, options: .TransitionFlipFromRight, animations: {
            self.contentView?.viewWithTag(1)?.hidden = false
            self.contentView?.viewWithTag(2)?.hidden = true
        }, completion: { complete in
        })

     } else {


        UIView.transitionWithView(self.contentView!, duration: 1, options: .TransitionFlipFromRight, animations: {
            self.contentView?.viewWithTag(1)?.hidden = true
            self.contentView?.viewWithTag(2)?.hidden = false
        }, completion: { complete in
        })
    }

    showingBack = !showingBack

}
+4
source share
2 answers

Unfortunately, the hidden object is not animated using the UIView animation. I believe that it is best to use fade, flip, etc., Or start Core Animation, which is much more powerful. Take a look at the documentation for UIView and Core Animations animations.

UIView.animateWithDuration(0.7, delay: 1.0, options: UIViewAnimationCurveEaseOut, animations: {
                        self.myView.frame = /* set the frame here */
  }, completion: { finished in
println("Done!")
  })
+2
source

Try this code ...

 func tapped() {
        if (showingBack) {
            UIView.transitionWithView(self.contentView!, duration: 1, options: .TransitionFlipFromRight, animations: {
                self.contentView?.alpha = 1.0
                self.Contentview2?.alpha = 0.0
                }, completion: { complete in

            })

        } else {


            UIView.transitionWithView(self.Contentview2!, duration: 1, options: .TransitionFlipFromRight, animations: {
                self.contentView?.alpha = 0.0
                self.Contentview2?.alpha = 1.0
                }, completion: { complete in

            })
        }

        showingBack = !showingBack

    }
+1

Source: https://habr.com/ru/post/1656668/


All Articles