Commit 58ad1c38 by Daniel Dahan Committed by GitHub

Merge pull request #432 from mohpor/development

Reverted changes to View Hierarchy to stabilize status bar animations
parents 11f9e26e 723ef9fa
...@@ -39,15 +39,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -39,15 +39,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let navigationController: AppNavigationController = AppNavigationController(rootViewController: RecipesViewController()) let navigationController: AppNavigationController = AppNavigationController(rootViewController: RecipesViewController())
let menuController: AppMenuController = AppMenuController(rootViewController: navigationController)
menuController.edgesForExtendedLayout = .None
let bottomNavigationController: BottomNavigationController = BottomNavigationController() let bottomNavigationController: BottomNavigationController = BottomNavigationController()
bottomNavigationController.viewControllers = [navigationController, VideoViewController(), PhotoViewController()] bottomNavigationController.viewControllers = [menuController, VideoViewController(), PhotoViewController()]
bottomNavigationController.selectedIndex = 0 bottomNavigationController.selectedIndex = 0
bottomNavigationController.tabBar.tintColor = MaterialColor.white bottomNavigationController.tabBar.tintColor = MaterialColor.white
bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4 bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4
let menuController: AppMenuController = AppMenuController(rootViewController: bottomNavigationController) let sideNavigationController: SideNavigationController = SideNavigationController(rootViewController: bottomNavigationController, leftViewController: AppLeftViewController())
let sideNavigationController: SideNavigationController = SideNavigationController(rootViewController: menuController, leftViewController: AppLeftViewController())
sideNavigationController.statusBarStyle = .LightContent sideNavigationController.statusBarStyle = .LightContent
window = UIWindow(frame: UIScreen.mainScreen().bounds) window = UIWindow(frame: UIScreen.mainScreen().bounds)
......
...@@ -40,11 +40,28 @@ class AppMenuController: MenuController { ...@@ -40,11 +40,28 @@ class AppMenuController: MenuController {
/// MenuView diameter. /// MenuView diameter.
private let baseSize: CGSize = CGSizeMake(56, 56) private let baseSize: CGSize = CGSizeMake(56, 56)
/// MenuView inset.
private let menuViewInset: CGFloat = 16
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(rootViewController: UIViewController) {
super.init(rootViewController: rootViewController)
prepareTabBarItem()
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareMenuView() prepareMenuView()
} }
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
closeMenu()
}
override func openMenu(completion: (() -> Void)? = nil) { override func openMenu(completion: (() -> Void)? = nil) {
super.openMenu(completion) super.openMenu(completion)
sideNavigationController?.enabled = false sideNavigationController?.enabled = false
...@@ -140,7 +157,14 @@ class AppMenuController: MenuController { ...@@ -140,7 +157,14 @@ class AppMenuController: MenuController {
menuView.delegate = self menuView.delegate = self
view.layout.size(menuView, width: baseSize.width, height: baseSize.height) view.layout.size(menuView, width: baseSize.width, height: baseSize.height)
view.layout.align.bottomRight(menuView, bottom: 65, right: 16) view.layout.align.bottomRight(menuView, bottom: menuViewInset, right: menuViewInset)
}
/// Prepare tabBarItem.
private func prepareTabBarItem() {
tabBarItem.image = MaterialIcon.cm.photoLibrary
tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal)
tabBarItem.setTitleColor(MaterialColor.white, forState: .Selected)
} }
} }
......
...@@ -35,7 +35,6 @@ class AppNavigationController: NavigationController { ...@@ -35,7 +35,6 @@ class AppNavigationController: NavigationController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareNavigationBar() prepareNavigationBar()
prepareTabBarItem()
} }
/// Prepares the navigationBar /// Prepares the navigationBar
...@@ -43,11 +42,4 @@ class AppNavigationController: NavigationController { ...@@ -43,11 +42,4 @@ class AppNavigationController: NavigationController {
navigationBar.tintColor = MaterialColor.white navigationBar.tintColor = MaterialColor.white
navigationBar.backgroundColor = MaterialColor.blue.base navigationBar.backgroundColor = MaterialColor.blue.base
} }
/// Prepare tabBarItem.
private func prepareTabBarItem() {
tabBarItem.image = MaterialIcon.cm.photoLibrary
tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal)
tabBarItem.setTitleColor(MaterialColor.white, forState: .Selected)
}
} }
...@@ -57,7 +57,6 @@ class ItemViewController: UIViewController { ...@@ -57,7 +57,6 @@ class ItemViewController: UIViewController {
convenience init(dataSource: MaterialDataSourceItem) { convenience init(dataSource: MaterialDataSourceItem) {
self.init(nibName: nil, bundle: nil) self.init(nibName: nil, bundle: nil)
self.dataSource = dataSource self.dataSource = dataSource
hidesBottomBarWhenPushed = true
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
...@@ -75,8 +74,11 @@ class ItemViewController: UIViewController { ...@@ -75,8 +74,11 @@ class ItemViewController: UIViewController {
override func viewWillAppear(animated: Bool) { override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
(menuController as? AppMenuController)?.hideMenu()
sideNavigationController?.enabled = false sideNavigationController?.enabled = false
// Stops the scrollView contentInsets from being automatically adjusted.
automaticallyAdjustsScrollViewInsets = false
(menuController as? AppMenuController)?.hideMenu()
} }
override func viewWillDisappear(animated: Bool) { override func viewWillDisappear(animated: Bool) {
...@@ -161,6 +163,9 @@ class ItemViewController: UIViewController { ...@@ -161,6 +163,9 @@ class ItemViewController: UIViewController {
let image: UIImage? = UIImage(named: data["image"] as! String) let image: UIImage? = UIImage(named: data["image"] as! String)
imageCardView.image = image imageCardView.image = image
scrollView.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false
} }
} }
} }
...@@ -70,6 +70,21 @@ class RecipesViewController: UIViewController { ...@@ -70,6 +70,21 @@ class RecipesViewController: UIViewController {
sideNavigationController?.enabled = true sideNavigationController?.enabled = true
} }
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// Show the menuView.
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
// Disable the SideNavigation.
// Hide the menuView.
}
/// Handles the menuButton. /// Handles the menuButton.
internal func handleMenuButton() { internal func handleMenuButton() {
sideNavigationController?.openLeftView() sideNavigationController?.openLeftView()
......
...@@ -287,18 +287,6 @@ public class NavigationBar : UINavigationBar { ...@@ -287,18 +287,6 @@ public class NavigationBar : UINavigationBar {
self.init(frame: CGRectZero) self.init(frame: CGRectZero)
} }
/// Calculates the offset for the statusbar.
private func statusbarOffset() -> CGFloat {
switch MaterialDevice.type {
case .iPad:
return MaterialDevice.statusBarHidden ? 20 : 0
case .iPhone:
return MaterialDevice.isPortrait && MaterialDevice.statusBarHidden ? 20 : 0
default:
return 0
}
}
public override func intrinsicContentSize() -> CGSize { public override func intrinsicContentSize() -> CGSize {
switch navigationBarStyle { switch navigationBarStyle {
case .Tiny: case .Tiny:
...@@ -311,9 +299,7 @@ public class NavigationBar : UINavigationBar { ...@@ -311,9 +299,7 @@ public class NavigationBar : UINavigationBar {
} }
public override func sizeThatFits(size: CGSize) -> CGSize { public override func sizeThatFits(size: CGSize) -> CGSize {
var result: CGSize = intrinsicContentSize() return intrinsicContentSize()
result.height += statusbarOffset()
return result
} }
public override func layoutSubviews() { public override func layoutSubviews() {
...@@ -337,7 +323,7 @@ public class NavigationBar : UINavigationBar { ...@@ -337,7 +323,7 @@ public class NavigationBar : UINavigationBar {
- Parameter item: A UINavigationItem to layout. - Parameter item: A UINavigationItem to layout.
*/ */
internal func layoutNavigationItem(item: UINavigationItem) { internal func layoutNavigationItem(item: UINavigationItem) {
if willRenderView && !animating { if willRenderView {
prepareItem(item) prepareItem(item)
if let titleView: UIView = prepareTitleView(item) { if let titleView: UIView = prepareTitleView(item) {
...@@ -345,7 +331,7 @@ public class NavigationBar : UINavigationBar { ...@@ -345,7 +331,7 @@ public class NavigationBar : UINavigationBar {
if let g: Int = Int(width / gridFactor) { if let g: Int = Int(width / gridFactor) {
let columns: Int = g + 1 let columns: Int = g + 1
titleView.frame.origin = CGPoint(x: 0, y: statusbarOffset()) titleView.frame.origin = CGPoint.zero
titleView.frame.size = intrinsicContentSize() titleView.frame.size = intrinsicContentSize()
titleView.grid.views = [] titleView.grid.views = []
titleView.grid.axis.columns = columns titleView.grid.axis.columns = columns
......
...@@ -400,6 +400,12 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -400,6 +400,12 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
// Portrait will be Lanscape when this method is done.
if MaterialDevice.isPortrait && .iPhone == MaterialDevice.type {
hideStatusBar()
} else {
showStatusBar()
}
closeLeftView() closeLeftView()
closeRightView() closeRightView()
...@@ -1092,17 +1098,9 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -1092,17 +1098,9 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
willHideStatusBar = false willHideStatusBar = false
UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration), UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
animations: { [weak self] in animations: { [weak self] in
if let v: NavigationBar = (self?.rootViewController as? NavigationController)?.navigationBar as? NavigationBar { self?.setNeedsStatusBarAppearanceUpdate()
v.animating = true
}
self?.statusBarHidden = false self?.statusBarHidden = false
})
}) { [weak self] _ in
if let v: NavigationBar = (self?.rootViewController as? NavigationController)?.navigationBar as? NavigationBar {
v.animating = false
}
}
self.setNeedsStatusBarAppearanceUpdate()
delegate?.sideNavigationStatusBarHiddenState?(self, hidden: false) delegate?.sideNavigationStatusBarHiddenState?(self, hidden: false)
} }
} }
...@@ -1114,17 +1112,9 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -1114,17 +1112,9 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
if !statusBarHidden { if !statusBarHidden {
UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration), UIView.animateWithDuration(NSTimeInterval(UINavigationControllerHideShowBarDuration),
animations: { [weak self] in animations: { [weak self] in
if let v: NavigationBar = (self?.rootViewController as? NavigationController)?.navigationBar as? NavigationBar { self?.setNeedsStatusBarAppearanceUpdate()
v.animating = true
}
self?.statusBarHidden = true self?.statusBarHidden = true
})
}) { [weak self] _ in
if let v: NavigationBar = (self?.rootViewController as? NavigationController)?.navigationBar as? NavigationBar {
v.animating = false
}
}
self.setNeedsStatusBarAppearanceUpdate()
delegate?.sideNavigationStatusBarHiddenState?(self, hidden: true) delegate?.sideNavigationStatusBarHiddenState?(self, hidden: true)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment