Learning notes for book iOS Animations by Tutorials.

First, what is the difference between transitionWithView and animationWithDuration?
animateWithDuration animates a UIView through changing its properties, whereas transitionWithView allows you to apply a transition to the specified view so that you can make state changes to it, such as add, remove, hide, show and replace one view with another view.

Then, here is an example. We added a hidden logging status view to the root view. After clicked the Login button, we show the status view. After 1.5 seconds, we hide the status view and refresh to the next status.

Image-1Image-1

The code looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
showMessage() {
UIView.transitionWithView(status, duration: 0.33, options: [.CurveEaseOut, .TransitionCurlDown], animations: {
self.status.hidden = false
}, completion: {_ in
delay(seconds: 1.5, completion: {
self.removeMessage()
})
})
}
removeMessage() {
UIView.animateWithDuration(0.33, delay: 0.0, options: [], animations: {
self.status.center.x += self.view.frame.size.width
}, completion: {_ in
self.status.hidden = true
self.showNextMessage()
})
}

The first parameter in transitionWithView() is the container view that performs the transition (Here is the status view). The rest of parameters are quite similar to the animateWithDuration().

Transition option:

  • .TransitionFlipFromLeft
  • .TransitionFlipFromRight
  • .TransitionCurlUp
  • .TransitionCurlDown
  • .TransitionCrossDissolve
  • .TransitionFlipFromTop
  • .TransitionFlipFromBottom