flip animation in swift flips whole view not subviews

后端 未结 2 1882
伪装坚强ぢ
伪装坚强ぢ 2021-01-06 14:39

I need to switch between two subviews, for that I am using flip animation, but it flips whole screen not subview. Here is the code I used to flip:

UIView.tra         


        
2条回答
  •  孤街浪徒
    2021-01-06 15:04

    This question is old, but it can help someone. If you want to flip your self.view use it:

    Swift 2

    UIView.transitionWithView(self.view, duration: 0.8, options: UIViewAnimationOptions.TransitionFlipFromRight | UIViewAnimationOptions.ShowHideTransitionViews, animations: {
        self.view.addSubview(newView)
    }, completion: { finished in
        // HERE you can remove your old view
        oldView.removeFromSuperview()
    })
    

    Swift 3, 4, 5

    UIView.transition(with: self.view, duration: 0.8, options: [UIView.AnimationOptions.transitionFlipFromRight, UIView.AnimationOptions.showHideTransitionViews], animations: {
        self.view.addSubview(newView)
    }, completion: { finished in
        // HERE you can remove your old view
        oldView.removeFromSuperview()
    })
    

提交回复
热议问题