Skip to content

Commit

Permalink
- added menuWillShow delegate method
Browse files Browse the repository at this point in the history
- ignore navigation bar height if it hidden
  • Loading branch information
Abdurahim Jauzee committed Apr 16, 2017
1 parent eeecad1 commit 958d4c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions DropdownMenu/DropUpMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public protocol DropUpMenuDelegate: class {
func dropUpMenu(_ dropUpMenu: DropUpMenu, didSelectRowAt indexPath: IndexPath)
func dropUpMenuCancel(_ dropUpMenu: DropUpMenu)
func dropUpMenuWillDismiss(_ dropUpMenu: DropUpMenu)
func dropUpMenuWillShow(_ dropUpMenu: DropUpMenu)
}

public extension DropUpMenuDelegate {
Expand All @@ -33,6 +34,8 @@ public extension DropUpMenuDelegate {
func dropUpMenuCancel(_ dropUpMenu: DropUpMenu) { }

func dropUpMenuWillDismiss(_ dropUpMenu: DropUpMenu) { }

func dropUpMenuWillShow(_ dropUpMenu: DropUpMenu) { }
}

private let screenRect = UIScreen.main.bounds
Expand Down Expand Up @@ -149,6 +152,7 @@ open class DropUpMenu: UIView {
}

open func showMenu() {
delegate?.dropUpMenuWillShow(self)
if isShow {
hideMenu()
return
Expand Down
9 changes: 8 additions & 1 deletion DropdownMenu/DropdownMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public protocol DropdownMenuDelegate: class {
func dropdownMenu(_ dropdownMenu: DropdownMenu, didSelectRowAt indexPath: IndexPath)
func dropdownMenuCancel(_ dropdownMenu: DropdownMenu)
func dropdownMenuWillDismiss(_ dropdownMenu: DropdownMenu)
func dropdownMenuWillShow(_ dropdownMenu: DropdownMenu)
}

public extension DropdownMenuDelegate {
func dropdownMenu(_ dropdownMenu: DropdownMenu, cellForRowAt indexPath: IndexPath) -> UITableViewCell? { return nil }
func dropdownMenu(_ dropdownMenu: DropdownMenu, didSelectRowAt indexPath: IndexPath) { }
func dropdownMenuCancel(_ dropdownMenu: DropdownMenu) { }
func dropdownMenuWillDismiss(_ dropdownMenu: DropdownMenu) { }
func dropdownMenuWillShow(_ dropdownMenu: DropdownMenu) { }
}

open class DropdownMenu: UIView {
Expand All @@ -36,7 +38,11 @@ open class DropdownMenu: UIView {
fileprivate let portraitTopOffset: CGFloat = 64.0
fileprivate let landscapeTopOffset: CGFloat = 32.0
fileprivate var topLayoutConstraintConstant: CGFloat {
return navigationController.navigationBar.frame.height + navigationController.navigationBar.frame.origin.y + topOffsetY
var offset: CGFloat = 0
if !navigationController.isNavigationBarHidden {
offset = navigationController.navigationBar.frame.height + navigationController.navigationBar.frame.origin.y
}
return offset + topOffsetY
}

open weak var delegate: DropdownMenuDelegate?
Expand Down Expand Up @@ -197,6 +203,7 @@ open class DropdownMenu: UIView {
}

open func showMenu(isOnNavigaitionView: Bool = false) {
delegate?.dropdownMenuWillShow(self)
if isShow {
hideMenu()
return
Expand Down

0 comments on commit 958d4c0

Please sign in to comment.