Guest User

Untitled

a guest
Jan 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. let initialFrame = CGRect(x: xpos, y: -310, width: 300, height: 300)
  2.  
  3. let firstView = UIView()
  4. firstView.backgroundColor = .red
  5. firstView.frame = initialFrame
  6.  
  7. let secondView = UIView()
  8. secondView.backgroundColor = .white
  9. secondView.frame = initialFrame
  10. secondView.isHidden = false
  11.  
  12.  
  13. self.view.addSubview(firstView)
  14. self.view.addSubview(secondView)
  15.  
  16.  
  17. // Here I try to move the views on screen while fliping them
  18. UIView.animate(withDuration: 1, delay: 0, options: .curveEaseOut, animations: {
  19. secondView.center = self.view.center
  20. firstView.center = self.view.center
  21. self.flip(firstView: firstView, secondView: secondView)
  22. }, completion: nil)
  23.  
  24.  
  25.  
  26. // This function flips the views vertically while it animates the transition from the first to the second view
  27. fileprivate func flip(firstView: UIView, secondView: UIView) {
  28. let transitionOptions: UIViewAnimationOptions = [.transitionFlipFromBottom, .showHideTransitionViews]
  29. UIView.transition(with: firstView, duration: 0.5, options: transitionOptions, animations: {
  30. firstView.isHidden = true
  31. })
  32.  
  33. UIView.transition(with: secondView, duration: 0.5, options: transitionOptions, animations: {
  34. secondView.isHidden = false
  35. })
  36. }
  37.  
  38. UIView.animate(withDuration: 1, delay: 0, options: .curveEaseOut, animations: {
  39. secondView.center = self.view.center
  40. firstView.center = self.view.center
  41. }, completion: {(_) in
  42. self.flip(firstView: dummyView, secondView: newGroupView)
  43. })
Add Comment
Please, Sign In to add comment