From 144a3830a384b04a6c53e5dcebe004e69fd0d95b Mon Sep 17 00:00:00 2001 From: Suric zhang <372081349@qq.com> Date: Thu, 11 Aug 2016 11:13:21 +0800 Subject: [PATCH] support dropUp menu form bottom --- DropdownMenu.xcodeproj/project.pbxproj | 4 + .../xcdebugger/Breakpoints_v2.xcbkptlist | 92 +++++++ DropdownMenu/DropUpMenu.swift | 256 ++++++++++++++++++ DropdownMenu/DropdownMenu.swift | 31 ++- .../project.pbxproj | 21 +- .../Base.lproj/Main.storyboard | 11 +- .../DropdownMenuDemo/ViewController.swift | 26 +- 7 files changed, 417 insertions(+), 24 deletions(-) create mode 100644 DropdownMenu/DropUpMenu.swift diff --git a/DropdownMenu.xcodeproj/project.pbxproj b/DropdownMenu.xcodeproj/project.pbxproj index ed9d15d..b7cf937 100644 --- a/DropdownMenu.xcodeproj/project.pbxproj +++ b/DropdownMenu.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + AC28BA811D5BAB25004F1663 /* DropUpMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC28BA801D5BAB25004F1663 /* DropUpMenu.swift */; }; AC4C1D5C1CF8325B006E36F5 /* DropdownItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC4C1D5B1CF8325B006E36F5 /* DropdownItem.swift */; }; ACE6DB701CF74183005C6667 /* DropdownMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = ACE6DB6F1CF74183005C6667 /* DropdownMenu.h */; settings = {ATTRIBUTES = (Public, ); }; }; ACE6DB771CF74183005C6667 /* DropdownMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ACE6DB6C1CF74183005C6667 /* DropdownMenu.framework */; }; @@ -25,6 +26,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + AC28BA801D5BAB25004F1663 /* DropUpMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropUpMenu.swift; sourceTree = ""; }; AC4C1D5B1CF8325B006E36F5 /* DropdownItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropdownItem.swift; sourceTree = ""; }; ACE6DB6C1CF74183005C6667 /* DropdownMenu.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DropdownMenu.framework; sourceTree = BUILT_PRODUCTS_DIR; }; ACE6DB6F1CF74183005C6667 /* DropdownMenu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DropdownMenu.h; sourceTree = ""; }; @@ -77,6 +79,7 @@ children = ( ACE6DB6F1CF74183005C6667 /* DropdownMenu.h */, ACE6DBC01CF74256005C6667 /* DropdownMenu.swift */, + AC28BA801D5BAB25004F1663 /* DropUpMenu.swift */, AC4C1D5B1CF8325B006E36F5 /* DropdownItem.swift */, ACE6DB711CF74183005C6667 /* Info.plist */, ); @@ -201,6 +204,7 @@ buildActionMask = 2147483647; files = ( ACE6DBC11CF74256005C6667 /* DropdownMenu.swift in Sources */, + AC28BA811D5BAB25004F1663 /* DropUpMenu.swift in Sources */, AC4C1D5C1CF8325B006E36F5 /* DropdownItem.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index ed9a9b4..a4eab33 100644 --- a/DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -2,4 +2,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DropdownMenu/DropUpMenu.swift b/DropdownMenu/DropUpMenu.swift new file mode 100644 index 0000000..20dca5d --- /dev/null +++ b/DropdownMenu/DropUpMenu.swift @@ -0,0 +1,256 @@ +// +// DropUpMenu.swift +// DropUpMenu +// +// Created by Suric on 16/8/11. +// Copyright © 2016年 teambition. All rights reserved. +// + +// +// DropUpMenu.swift +// DropUpMenu +// +// Created by Suric on 16/5/26. +// Copyright © 2016年 teambition. All rights reserved. +// + +import UIKit + +public protocol DropUpMenuDelegate: class { + func dropUpMenu(dropUpMenu: DropUpMenu, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell? + func dropUpMenu(dropUpMenu: DropUpMenu, didSelectRowAtIndexPath indexPath: NSIndexPath) +} + +public extension DropUpMenuDelegate { + func dropUpMenu(dropUpMenu: DropUpMenu, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell? { + return nil + } + + func dropUpMenu(dropUpMenu: DropUpMenu, didSelectRowAtIndexPath indexPath: NSIndexPath) { + } +} + +private let screenRect = UIScreen.mainScreen().bounds + +public class DropUpMenu: UIView { + private var items: [DropdownItem] = [] + private var selectedRow: Int + public var tableView: UITableView! + private var barCoverView: UIView! + private var isShow = false + private var addedWindow: UIWindow? + private var windowRootView: UIView? + private lazy var tapGestureRecognizer: UITapGestureRecognizer = { + return UITapGestureRecognizer(target: self, action: #selector(self.hideMenu)) + }() + + public weak var delegate: DropUpMenuDelegate? + public var animateDuration: NSTimeInterval = 0.25 + public var backgroudBeginColor: UIColor = UIColor.blackColor().colorWithAlphaComponent(0) + public var backgroudEndColor = UIColor(white: 0, alpha: 0.4) + public var rowHeight: CGFloat = 50 + public var tableViewHeight: CGFloat = 0 + public var defaultBottonMargin: CGFloat = 150 + public var textColor: UIColor = UIColor(red: 56.0/255.0, green: 56.0/255.0, blue: 56.0/255.0, alpha: 1.0) + public var highlightColor: UIColor = UIColor(red: 3.0/255.0, green: 169.0/255.0, blue: 244.0/255.0, alpha: 1.0) + public var tableViewBackgroundColor: UIColor = UIColor(red: 242.0/255.0, green: 242.0/255.0, blue: 242.0/255.0, alpha: 1.0) + public var tableViewSeperatorColor = UIColor(red: 217.0/255.0, green: 217.0/255.0, blue: 217.0/255.0, alpha: 1.0) + public var displaySelected: Bool = true + public var bottomOffsetY: CGFloat = 0 + + required public init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public init(items: [DropdownItem], selectedRow: Int = 0, bottomOffsetY: CGFloat = 0) { + self.items = items + self.selectedRow = selectedRow + self.bottomOffsetY = bottomOffsetY + + let frame = CGRect(x: 0, y: 0, width: screenRect.width, height: screenRect.height - bottomOffsetY) + super.init(frame: frame) + + clipsToBounds = true + setupGestureView() + setupTableView() + } + + private func setupGestureView() { + let gestureView = UIView() + gestureView.backgroundColor = UIColor.clearColor() + addSubview(gestureView) + gestureView.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: gestureView, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Top, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: gestureView, attribute: .Bottom, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: gestureView, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: gestureView, attribute: .Right, relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1.0, constant: 0)]) + + gestureView.addGestureRecognizer(tapGestureRecognizer) + } + + private func setupTopSeperatorView() { + let seperatorView = UIView() + seperatorView.backgroundColor = tableViewSeperatorColor + addSubview(seperatorView) + seperatorView.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: seperatorView, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Top, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: seperatorView, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: seperatorView, attribute: .Right, relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: seperatorView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 0.5)]) + } + + private func setupTableView() { + tableViewHeight = CGFloat(items.count) * rowHeight + let maxHeight = UIScreen.mainScreen().bounds.height - bottomOffsetY + if tableViewHeight > maxHeight { + tableViewHeight = maxHeight + } + + tableView = UITableView(frame: CGRect.zero, style: .Grouped) + tableView.separatorColor = tableViewSeperatorColor + tableView.backgroundColor = tableViewBackgroundColor + tableView?.delegate = self + tableView?.dataSource = self + addSubview(tableView) + tableView.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: tableView, attribute: .Bottom, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1.0, constant:0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: tableView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: tableViewHeight)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: tableView, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: tableView, attribute: .Right, relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1.0, constant: 0)]) + } + + private func setupBottomCoverView(onView: UIView) { + barCoverView = UIView() + barCoverView.backgroundColor = UIColor.clearColor() + barCoverView.translatesAutoresizingMaskIntoConstraints = false + onView.addSubview(barCoverView) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: barCoverView, attribute: .Bottom, relatedBy: .Equal, toItem: onView, attribute: .Bottom, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: barCoverView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: bottomOffsetY)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: barCoverView, attribute: .Left, relatedBy: .Equal, toItem: onView, attribute: .Left, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: barCoverView, attribute: .Right, relatedBy: .Equal, toItem: onView, attribute: .Right, multiplier: 1.0, constant: 0)]) + barCoverView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hideMenu))) + } + + public func showMenu() { + if isShow { + hideMenu() + return + } + isShow = true + + if let rootView = UIApplication.sharedApplication().keyWindow { + windowRootView = rootView + } else { + addedWindow = UIWindow(frame: UIScreen.mainScreen().bounds) + addedWindow?.rootViewController = UIViewController() + addedWindow?.hidden = false + addedWindow?.makeKeyAndVisible() + windowRootView = addedWindow! + } + setupBottomCoverView(windowRootView!) + windowRootView?.addSubview(self) + + translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: self, attribute: .Top, relatedBy: .Equal, toItem: windowRootView, attribute: .Top, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: self, attribute: .Bottom, relatedBy: .Equal, toItem: windowRootView, attribute: .Bottom, multiplier: 1.0, constant: -bottomOffsetY)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: self, attribute: .Left, relatedBy: .Equal, toItem: windowRootView, attribute: .Left, multiplier: 1.0, constant: 0)]) + NSLayoutConstraint.activateConstraints([NSLayoutConstraint.init(item: self, attribute: .Right, relatedBy: .Equal, toItem: windowRootView, attribute: .Right, multiplier: 1.0, constant: 0)]) + + backgroundColor = backgroudBeginColor + self.tableView.frame.origin.y = screenRect.height - bottomOffsetY + UIView.animateWithDuration(animateDuration, delay: 0, options: UIViewAnimationOptions(rawValue: 7<<16), animations: { + self.backgroundColor = self.backgroudEndColor + self.tableView.frame.origin.y = screenRect.height - self.bottomOffsetY - self.tableViewHeight + }, completion: nil) + } + + public func hideMenu() { + UIView.animateWithDuration(animateDuration, animations: { + self.backgroundColor = self.backgroudBeginColor + self.tableView.frame.origin.y = screenRect.height - self.bottomOffsetY + }) { (finished) in + self.barCoverView.removeFromSuperview() + self.removeFromSuperview() + self.isShow = false + + if let _ = self.addedWindow { + self.addedWindow?.hidden = true + UIApplication.sharedApplication().keyWindow?.makeKeyWindow() + } + } + } +} + +extension DropUpMenu: UITableViewDataSource { + public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return items.count + } + + public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { + return rowHeight + } + + public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + if let customCell = delegate?.dropUpMenu(self, cellForRowAtIndexPath: indexPath) { + return customCell + } + let item = items[indexPath.row] + let cell = UITableViewCell(style: .Default, reuseIdentifier: "dropUpMenuCell") + + switch item.style { + case .Default: + cell.textLabel?.textColor = textColor + if let image = item.image { + cell.imageView?.image = image + } + case .Highlight: + cell.textLabel?.textColor = highlightColor + if let image = item.image { + let highlightImage = image.imageWithRenderingMode(.AlwaysTemplate) + cell.imageView?.image = highlightImage + cell.imageView?.tintColor = highlightColor + } + } + + cell.textLabel?.text = item.title + cell.tintColor = highlightColor + if displaySelected && indexPath.row == selectedRow { + cell.accessoryType = .Checkmark + } else { + cell.accessoryType = .None + } + + if let accesoryImage = item.accessoryImage { + cell.accessoryView = UIImageView(image: accesoryImage) + } + + return cell + } +} + +extension DropUpMenu: UITableViewDelegate { + public func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return CGFloat.min + } + + public func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + return CGFloat.min + } + + public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + if displaySelected { + let item = items[indexPath.row] + if item.accessoryImage == nil { + let previousSelectedcell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: selectedRow, inSection: 0)) + previousSelectedcell?.accessoryType = .None + selectedRow = indexPath.row + let cell = tableView.cellForRowAtIndexPath(indexPath) + cell?.accessoryType = .Checkmark + } + } + tableView.deselectRowAtIndexPath(indexPath, animated: true) + hideMenu() + delegate?.dropUpMenu(self, didSelectRowAtIndexPath: indexPath) + } +} + diff --git a/DropdownMenu/DropdownMenu.swift b/DropdownMenu/DropdownMenu.swift index 300dbe2..37e50cf 100644 --- a/DropdownMenu/DropdownMenu.swift +++ b/DropdownMenu/DropdownMenu.swift @@ -8,9 +8,18 @@ import UIKit -@objc public protocol DropdownMenuDelegate: NSObjectProtocol { - optional func dropdownMenu(dropdownMenu: DropdownMenu, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell - optional func dropdownMenu(dropdownMenu: DropdownMenu, didSelectRowAtIndexPath indexPath: NSIndexPath) +public protocol DropdownMenuDelegate: class { + func dropdownMenu(dropdownMenu: DropdownMenu, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell? + func dropdownMenu(dropdownMenu: DropdownMenu, didSelectRowAtIndexPath indexPath: NSIndexPath) +} + +public extension DropdownMenuDelegate { + func dropdownMenu(dropdownMenu: DropdownMenu, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell? { + return nil + } + + func dropdownMenu(dropdownMenu: DropdownMenu, didSelectRowAtIndexPath indexPath: NSIndexPath) { + } } public class DropdownMenu: UIView { @@ -43,10 +52,8 @@ public class DropdownMenu: UIView { self.navigationController = navigationController self.items = items self.selectedRow = selectedRow - - let navigationBarFrame: CGRect = navigationController.navigationBar.frame - let menuFrame: CGRect = CGRect(x: 0, y: (navigationBarFrame.height + navigationBarFrame.origin.y), width: navigationBarFrame.width, height: navigationController.view.frame.height - navigationBarFrame.height - navigationBarFrame.origin.y) - super.init(frame: menuFrame) + + super.init(frame: CGRect.zero) clipsToBounds = true setupGestureView() @@ -127,7 +134,7 @@ public class DropdownMenu: UIView { windowRootView = navigationController.view windowRootView.insertSubview(self, belowSubview: navigationController.navigationBar) } else { - if let rootView = UIApplication.sharedApplication().keyWindow?.rootViewController?.view { + if let rootView = UIApplication.sharedApplication().keyWindow { windowRootView = rootView windowRootView.addSubview(self) } else { @@ -143,10 +150,10 @@ public class DropdownMenu: UIView { backgroundColor = backgroudBeginColor self.tableView.frame.origin.y = -self.tableViewHeight - UIView.animateWithDuration(animateDuration) { + UIView.animateWithDuration(animateDuration, delay: 0, options: UIViewAnimationOptions(rawValue: 7<<16), animations: { self.backgroundColor = self.backgroudEndColor self.tableView.frame.origin.y = 0 - } + }, completion: nil) } public func hideMenu() { @@ -171,7 +178,7 @@ extension DropdownMenu: UITableViewDataSource { } public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - if let customCell = delegate?.dropdownMenu?(self, cellForRowAtIndexPath: indexPath) { + if let customCell = delegate?.dropdownMenu(self, cellForRowAtIndexPath: indexPath) { return customCell } let item = items[indexPath.row] @@ -230,6 +237,6 @@ extension DropdownMenu: UITableViewDelegate { } tableView.deselectRowAtIndexPath(indexPath, animated: true) hideMenu() - delegate?.dropdownMenu?(self, didSelectRowAtIndexPath: indexPath) + delegate?.dropdownMenu(self, didSelectRowAtIndexPath: indexPath) } } diff --git a/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj b/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj index 06f28ad..b8804a3 100644 --- a/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj +++ b/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj @@ -7,9 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - AC4C1D681CF934B6006E36F5 /* DropdownMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC4C1D671CF934B6006E36F5 /* DropdownMenu.framework */; }; - AC4C1D691CF934B9006E36F5 /* DropdownMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC4C1D671CF934B6006E36F5 /* DropdownMenu.framework */; }; - AC4C1D6A1CF934B9006E36F5 /* DropdownMenu.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = AC4C1D671CF934B6006E36F5 /* DropdownMenu.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + AC28BA7F1D5BA287004F1663 /* DropdownMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC28BA7E1D5BA287004F1663 /* DropdownMenu.framework */; }; ACE6DB931CF741F6005C6667 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACE6DB921CF741F6005C6667 /* AppDelegate.swift */; }; ACE6DB951CF741F6005C6667 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACE6DB941CF741F6005C6667 /* ViewController.swift */; }; ACE6DB981CF741F6005C6667 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ACE6DB961CF741F6005C6667 /* Main.storyboard */; }; @@ -52,7 +50,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - AC4C1D6A1CF934B9006E36F5 /* DropdownMenu.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -60,7 +57,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - AC4C1D671CF934B6006E36F5 /* DropdownMenu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DropdownMenu.framework; path = "../../../../Library/Developer/Xcode/DerivedData/DropdownMenu-elwexzlgcvbowbesmsdmavblsccq/Build/Products/Debug-iphoneos/DropdownMenu.framework"; sourceTree = ""; }; + AC28BA7E1D5BA287004F1663 /* DropdownMenu.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DropdownMenu.framework; path = "../../../../Library/Developer/Xcode/DerivedData/DropdownMenu-elwexzlgcvbowbesmsdmavblsccq/Build/Products/Debug-iphonesimulator/DropdownMenu.framework"; sourceTree = ""; }; ACE6DB8F1CF741F6005C6667 /* DropdownMenuDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DropdownMenuDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; ACE6DB921CF741F6005C6667 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; ACE6DB941CF741F6005C6667 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -81,8 +78,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - AC4C1D691CF934B9006E36F5 /* DropdownMenu.framework in Frameworks */, - AC4C1D681CF934B6006E36F5 /* DropdownMenu.framework in Frameworks */, + AC28BA7F1D5BA287004F1663 /* DropdownMenu.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -106,7 +102,7 @@ ACE6DB861CF741F6005C6667 = { isa = PBXGroup; children = ( - AC4C1D671CF934B6006E36F5 /* DropdownMenu.framework */, + AC28BA7E1D5BA287004F1663 /* DropdownMenu.framework */, ACE6DB911CF741F6005C6667 /* DropdownMenuDemo */, ACE6DBA61CF741F6005C6667 /* DropdownMenuDemoTests */, ACE6DBB11CF741F6005C6667 /* DropdownMenuDemoUITests */, @@ -225,13 +221,16 @@ TargetAttributes = { ACE6DB8E1CF741F6005C6667 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; }; ACE6DBA21CF741F6005C6667 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; TestTargetID = ACE6DB8E1CF741F6005C6667; }; ACE6DBAD1CF741F6005C6667 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; TestTargetID = ACE6DB8E1CF741F6005C6667; }; }; @@ -437,6 +436,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; }; name = Debug; }; @@ -448,6 +448,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; }; name = Release; }; @@ -459,6 +460,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DropdownMenuDemo.app/DropdownMenuDemo"; }; name = Debug; @@ -471,6 +473,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DropdownMenuDemo.app/DropdownMenuDemo"; }; name = Release; @@ -482,6 +485,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoUITests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; TEST_TARGET_NAME = DropdownMenuDemo; }; name = Debug; @@ -493,6 +497,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoUITests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; TEST_TARGET_NAME = DropdownMenuDemo; }; name = Release; diff --git a/DropdownMenuDemo/DropdownMenuDemo/Base.lproj/Main.storyboard b/DropdownMenuDemo/DropdownMenuDemo/Base.lproj/Main.storyboard index 6e0f05d..5bdcf04 100644 --- a/DropdownMenuDemo/DropdownMenuDemo/Base.lproj/Main.storyboard +++ b/DropdownMenuDemo/DropdownMenuDemo/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -31,11 +31,16 @@ - + + + + + + @@ -74,7 +79,7 @@ - + diff --git a/DropdownMenuDemo/DropdownMenuDemo/ViewController.swift b/DropdownMenuDemo/DropdownMenuDemo/ViewController.swift index 6dd0a4d..7470e64 100644 --- a/DropdownMenuDemo/DropdownMenuDemo/ViewController.swift +++ b/DropdownMenuDemo/DropdownMenuDemo/ViewController.swift @@ -31,8 +31,21 @@ class ViewController: UIViewController { items = [item1, item2, item3, item4] let menuView = DropdownMenu(navigationController: navigationController!, items: items, selectedRow: selectedRow) menuView.delegate = self - menuView.showMenu(onNavigaitionView: true) + menuView.showMenu(onNavigaitionView: false) } + + @IBAction func dropUpAction(sender: AnyObject) { + let item1 = DropdownItem(title: "NO Image") + let item2 = DropdownItem(image: UIImage(named: "file")!, title: "File") + let item3 = DropdownItem(image: UIImage(named: "post")!, title: "Post", style: .Highlight) + let item4 = DropdownItem(image: UIImage(named: "post")!, title: "Event", style: .Highlight, accessoryImage: UIImage(named: "accessory")!) + + items = [item1, item2, item3, item4] + let menuView = DropUpMenu(items: items, selectedRow: 0, bottomOffsetY: self.tabBarController?.tabBar.frame.height ?? 0) + menuView.delegate = self + menuView.showMenu() + } + } extension ViewController: DropdownMenuDelegate { @@ -50,3 +63,14 @@ extension ViewController: DropdownMenuDelegate { } } } + +extension ViewController: DropUpMenuDelegate { + func dropUpMenu(dropUpMenu: DropUpMenu, didSelectRowAtIndexPath indexPath: NSIndexPath) { + let alertConroller = UIAlertController(title: "Nice", message: "DropUpMenu didselect \(indexPath.row) text:\(items[indexPath.row].title)", preferredStyle: .Alert) + let okAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil) + alertConroller.addAction(okAction) + presentViewController(alertConroller, animated: true) { + print("Display success") + } + } +}