A simple project that shows how implementing states makes it easier to manage and update UI animations by defining each element's behavior for a given state.
The project has a simple login screen with 4 different states:
enum LoginState {
case initial, waiting, invalidEmail, ready
}
- Initial: When the view controller has been loaded on the screen.
- Waiting: Waiting for the user to type in email and password.
- Invalid email: The entered email is not valid. An error message is displayed.
- Ready: The data has been successfully validated and the user is now allowed to attempt to log in.
Transition between states can be easily achieved by simply updating the view controller's current state.
let animations = { [weak self] in
self?.state = .ready
self?.view.layoutIfNeeded()
}
self.view.layoutIfNeeded()
UIView.animate(withDuration: 0.3,
delay: 0.0,
options: .curveEaseInOut,
animations: animations,
completion: nil)
ViewControllerStates is released under the MIT license. See license for details.