diff --git a/DropdownMenu.xcodeproj/project.pbxproj b/DropdownMenu.xcodeproj/project.pbxproj index dff4ff8..de08a39 100644 --- a/DropdownMenu.xcodeproj/project.pbxproj +++ b/DropdownMenu.xcodeproj/project.pbxproj @@ -161,22 +161,24 @@ ACE6DB6B1CF74183005C6667 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 7NLBE99QC4; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; ACE6DB751CF74183005C6667 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 7NLBE99QC4; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; }; }; buildConfigurationList = ACE6DB661CF74183005C6667 /* Build configuration list for PBXProject "DropdownMenu" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = ACE6DB621CF74183005C6667; productRefGroup = ACE6DB6D1CF74183005C6667 /* Products */; @@ -369,7 +371,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -390,7 +392,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenu; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -403,7 +405,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -416,7 +418,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/DropdownMenu.xcworkspace/xcuserdata/wangwei.xcuserdatad/UserInterfaceState.xcuserstate b/DropdownMenu.xcworkspace/xcuserdata/wangwei.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index 174cc3f..0000000 Binary files a/DropdownMenu.xcworkspace/xcuserdata/wangwei.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/DropdownMenu.xcworkspace/xcuserdata/wangwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DropdownMenu.xcworkspace/xcuserdata/wangwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index ed9a9b4..0000000 --- a/DropdownMenu.xcworkspace/xcuserdata/wangwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist deleted file mode 100644 index 1071dcf..0000000 --- a/DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - diff --git a/DropdownMenu/DropUpMenu.swift b/DropdownMenu/DropUpMenu.swift index 1ab9c30..685b825 100644 --- a/DropdownMenu/DropUpMenu.swift +++ b/DropdownMenu/DropUpMenu.swift @@ -33,14 +33,24 @@ public extension DropUpMenuDelegate { private let screenRect = UIScreen.main.bounds open class DropUpMenu: UIView { - fileprivate var items: [DropdownItem] = [] - fileprivate var selectedRow: Int - open var tableView: UITableView! - fileprivate var barCoverView: UIView! - fileprivate var isShow = false - fileprivate var addedWindow: UIWindow? - fileprivate var windowRootView: UIView? - fileprivate lazy var tapGestureRecognizer: UITapGestureRecognizer = { + private var items: [DropdownItem] = [] + private var selectedRow: Int + open lazy var tableView: UITableView = { + let tableView = UITableView(frame: CGRect.zero, style: .grouped) + tableView.estimatedSectionHeaderHeight = 0 + tableView.estimatedSectionFooterHeight = 0 + return tableView + }() + private lazy var barCoverView: UIView = { + let barCoverView = UIView() + barCoverView.backgroundColor = UIColor.clear + barCoverView.translatesAutoresizingMaskIntoConstraints = false + return barCoverView + }() + 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)) }() @@ -86,10 +96,10 @@ open class DropUpMenu: UIView { clipsToBounds = true setupGestureView() - initTableView() + setupTableView() } - fileprivate func setupGestureView() { + private func setupGestureView() { let gestureView = UIView() gestureView.backgroundColor = UIColor.clear addSubview(gestureView) @@ -102,16 +112,13 @@ open class DropUpMenu: UIView { gestureView.addGestureRecognizer(tapGestureRecognizer) } - fileprivate func initTableView() { - tableView = UITableView(frame: CGRect.zero, style: .grouped) - tableView?.delegate = self - tableView?.dataSource = self - tableView.estimatedSectionHeaderHeight = 0 - tableView.estimatedSectionFooterHeight = 0 + private func setupTableView() { + tableView.delegate = self + tableView.dataSource = self addSubview(tableView) } - fileprivate func layoutTableView() { + private func layoutTableView() { tableViewHeight = CGFloat(items.count) * rowHeight let maxHeight = UIScreen.main.bounds.height - bottomOffsetY if tableViewHeight > maxHeight { @@ -125,7 +132,7 @@ open class DropUpMenu: UIView { NSLayoutConstraint.activate([NSLayoutConstraint.init(item: tableView, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 0)]) } - fileprivate func setupBottomSeperatorView() { + private func setupBottomSeperatorView() { let seperatorView = UIView() seperatorView.backgroundColor = tableViewSeperatorColor addSubview(seperatorView) @@ -136,10 +143,7 @@ open class DropUpMenu: UIView { NSLayoutConstraint.activate([NSLayoutConstraint.init(item: seperatorView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 0.5)]) } - fileprivate func setupBottomCoverView(on view: UIView) { - barCoverView = UIView() - barCoverView.backgroundColor = UIColor.clear - barCoverView.translatesAutoresizingMaskIntoConstraints = false + private func setupBottomCoverView(on view: UIView) { view.addSubview(barCoverView) NSLayoutConstraint.activate([NSLayoutConstraint.init(item: barCoverView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1.0, constant: 0)]) NSLayoutConstraint.activate([NSLayoutConstraint.init(item: barCoverView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: bottomOffsetY)]) diff --git a/DropdownMenu/DropdownMenu.swift b/DropdownMenu/DropdownMenu.swift index 742c9cd..0022bf3 100644 --- a/DropdownMenu/DropdownMenu.swift +++ b/DropdownMenu/DropdownMenu.swift @@ -33,23 +33,28 @@ public extension DropdownMenuDelegate { } open class DropdownMenu: UIView { - fileprivate weak var navigationController: UINavigationController! + private weak var navigationController: UINavigationController! - fileprivate var sections: [DropdownSection] = [] - fileprivate var selectedIndexPath: IndexPath + private var sections: [DropdownSection] = [] + private var selectedIndexPath: IndexPath - open var tableView: UITableView! - fileprivate var barCoverView: UIView? + open var tableView: UITableView = { + let tableView = UITableView(frame: CGRect.zero, style: .grouped) + tableView.estimatedSectionFooterHeight = 0 + tableView.estimatedSectionHeaderHeight = 0 + return tableView + }() + private var barCoverView: UIView? open var isShow = false - fileprivate var addedWindow: UIWindow? - fileprivate var windowRootView: UIView? - fileprivate var topConstraint: NSLayoutConstraint? - fileprivate var navigationBarCoverViewHeightConstraint: NSLayoutConstraint? - fileprivate var tableViewHeightConstraint: NSLayoutConstraint? - fileprivate let iPhoneXPortraitTopOffset: CGFloat = 88.0 - fileprivate let portraitTopOffset: CGFloat = 64.0 - fileprivate let landscapeTopOffset: CGFloat = 32.0 - fileprivate var topLayoutConstraintConstant: CGFloat { + private var addedWindow: UIWindow? + private var windowRootView: UIView? + private var topConstraint: NSLayoutConstraint? + private var navigationBarCoverViewHeightConstraint: NSLayoutConstraint? + private var tableViewHeightConstraint: NSLayoutConstraint? + private let iPhoneXPortraitTopOffset: CGFloat = 88.0 + private let portraitTopOffset: CGFloat = 64.0 + private let landscapeTopOffset: CGFloat = 32.0 + private var topLayoutConstraintConstant: CGFloat { var offset: CGFloat = 0 if !navigationController.isNavigationBarHidden { offset = navigationController.navigationBar.frame.height + navigationController.navigationBar.frame.origin.y @@ -108,7 +113,7 @@ open class DropdownMenu: UIView { clipsToBounds = true setupGestureView() - initTableView() + setupTableView() NotificationCenter.default.addObserver(self, selector: #selector(self.updateForOrientationChange(_:)), name: UIApplication.willChangeStatusBarOrientationNotification, object: nil) } @@ -123,7 +128,7 @@ open class DropdownMenu: UIView { clipsToBounds = true setupGestureView() - initTableView() + setupTableView() NotificationCenter.default.addObserver(self, selector: #selector(self.updateForOrientationChange(_:)), name: UIApplication.willChangeStatusBarOrientationNotification, object: nil) } @@ -186,7 +191,7 @@ open class DropdownMenu: UIView { } } - fileprivate func setupGestureView() { + private func setupGestureView() { let gestureView = UIView() gestureView.backgroundColor = UIColor.clear addSubview(gestureView) @@ -199,17 +204,14 @@ open class DropdownMenu: UIView { gestureView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hideMenu))) } - fileprivate func initTableView() { - tableView = UITableView(frame: CGRect.zero, style: .grouped) + private func setupTableView() { tableView.separatorStyle = separatorStyle tableView.delegate = self tableView.dataSource = self - tableView.estimatedSectionFooterHeight = 0 - tableView.estimatedSectionHeaderHeight = 0 addSubview(tableView) } - fileprivate func layoutTableView() { + private func layoutTableView() { tableView.translatesAutoresizingMaskIntoConstraints = false updateTableViewHeight() @@ -222,7 +224,7 @@ open class DropdownMenu: UIView { self.tableViewHeightConstraint = tableViewHeightConstraint } - fileprivate func updateTableViewHeight() { + private func updateTableViewHeight() { tableViewHeight = tableviewHeight() let maxHeight = navigationController.view.frame.height - topLayoutConstraintConstant - defaultBottonMargin @@ -236,7 +238,7 @@ open class DropdownMenu: UIView { } } - fileprivate func updateForSectionsChange(_ animations: (() -> Void)? = nil) { + private func updateForSectionsChange(_ animations: (() -> Void)? = nil) { updateTableViewHeight() tableViewHeightConstraint?.constant = tableViewHeight UIView.animate(withDuration: 0.3) { [weak self] in @@ -248,7 +250,7 @@ open class DropdownMenu: UIView { } } - fileprivate func setupTopSeperatorView() { + private func setupTopSeperatorView() { let seperatorView = UIView() seperatorView.backgroundColor = tableViewSeperatorColor addSubview(seperatorView) @@ -259,7 +261,7 @@ open class DropdownMenu: UIView { NSLayoutConstraint.activate([NSLayoutConstraint.init(item: seperatorView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 0.5)]) } - fileprivate func setupNavigationBarCoverView(on view: UIView) { + private func setupNavigationBarCoverView(on view: UIView) { barCoverView = UIView() barCoverView?.backgroundColor = UIColor.clear view.addSubview(barCoverView!) @@ -273,7 +275,7 @@ open class DropdownMenu: UIView { barCoverView?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hideMenu))) } - fileprivate func tableviewHeight() -> CGFloat { + private func tableviewHeight() -> CGFloat { var height: CGFloat = 0 sections.enumerated().forEach { if displaySectionHeader { diff --git a/DropdownMenu/SectionHeader.swift b/DropdownMenu/SectionHeader.swift index ca39a21..f8fda7f 100644 --- a/DropdownMenu/SectionHeader.swift +++ b/DropdownMenu/SectionHeader.swift @@ -7,7 +7,12 @@ // open class SectionHeader: UIView { - var titleLabel: UILabel! + var titleLabel: UILabel = { + let titleLabel = UILabel() + titleLabel.translatesAutoresizingMaskIntoConstraints = false + return titleLabel + }() + var style: SectionHeaderStyle = SectionHeaderStyle() convenience init(style: SectionHeaderStyle) { @@ -25,8 +30,6 @@ open class SectionHeader: UIView { } func commonInit() { - titleLabel = UILabel() - titleLabel.translatesAutoresizingMaskIntoConstraints = false titleLabel.font = style.font titleLabel.textColor = style.textColor backgroundColor = style.backgroundColor diff --git a/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj b/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj index ecb07d9..586e282 100644 --- a/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj +++ b/DropdownMenuDemo/DropdownMenuDemo.xcodeproj/project.pbxproj @@ -224,25 +224,25 @@ ACE6DB8E1CF741F6005C6667 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = ZDUX4TJC7F; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; }; ACE6DBA21CF741F6005C6667 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 7NLBE99QC4; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; TestTargetID = ACE6DB8E1CF741F6005C6667; }; ACE6DBAD1CF741F6005C6667 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 7NLBE99QC4; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; TestTargetID = ACE6DB8E1CF741F6005C6667; }; }; }; buildConfigurationList = ACE6DB8A1CF741F6005C6667 /* Build configuration list for PBXProject "DropdownMenuDemo" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -400,7 +400,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -450,7 +450,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -466,7 +466,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenu2; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -480,7 +480,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenu2; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -493,7 +493,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DropdownMenuDemo.app/DropdownMenuDemo"; }; name = Debug; @@ -507,7 +507,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DropdownMenuDemo.app/DropdownMenuDemo"; }; name = Release; @@ -520,7 +520,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = DropdownMenuDemo; }; name = Debug; @@ -533,7 +533,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuDemoUITests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = DropdownMenuDemo; }; name = Release; diff --git a/DropdownMenuTests/DropdownMenuTests.swift b/DropdownMenuTests/DropdownMenuTests.swift index be0825e..bd89027 100644 --- a/DropdownMenuTests/DropdownMenuTests.swift +++ b/DropdownMenuTests/DropdownMenuTests.swift @@ -28,7 +28,7 @@ class DropdownMenuTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock { + self.measure { // Put the code you want to measure the time of here. } }