| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import UIKit
- public protocol NavigationBarInOutAnimator: class {
- var navigationView: UIView { get }
- func navigationBarFadeIn()
- func navigationBarFadeOut()
- func navigationBarFadeAndMoveIn()
- func navigationBarFadeAndMoveOut()
- func navigationBarFadeOutWithPercentage(_ percentage: CGFloat)
- func navigationBarFadeInWithPercentage(_ percentage: CGFloat)
- }
- public extension NavigationBarInOutAnimator where Self: UIViewController & NavigationBarPushAndPopDelegate {
- func navigationBarFadeIn() {
- UIView.animate(withDuration: 0.3, animations: {
- self.navigationView.alpha = 1
- }, completion: nil)
- }
-
- func navigationBarFadeOut() {
- UIView.animate(withDuration: 0.3, animations: {
- self.navigationView.alpha = 0
- }, completion: nil)
- }
-
- func navigationBarFadeAndMoveIn() {
- setNavigationBar()
- navigationController?.navigationBar.layoutIfNeeded()
-
- let originX = navigationView.center.x
- navigationView.center.x = UIScreen.main.bounds.width
-
- UIView.animate(withDuration: 0.3, animations: {
- self.navigationView.alpha = 1
- self.navigationView.center.x = originX
- }, completion: nil)
- }
-
- func navigationBarFadeAndMoveOut() {
- UIView.animate(withDuration: 0.3, animations: {
- self.navigationView.alpha = 0
- self.navigationView.center.x = UIScreen.main.bounds.width
- }, completion: { _ in
- self.navigationView.removeFromSuperview()
- })
- }
-
- func navigationBarFadeOutWithPercentage(_ percentage: CGFloat) {
- navigationView.alpha = 1 * (1 - 1.1 * percentage)
- navigationView.center.x = UIScreen.main.bounds.width / 2 * (1 + 1.1 * percentage)
- }
-
- func navigationBarFadeInWithPercentage(_ percentage: CGFloat) {
- navigationView.alpha = 1 * percentage
- }
- }
|