From 52f3ab93b39c3af50f183124a0432c23ad3fe0cc Mon Sep 17 00:00:00 2001 From: Adrian Mateoaea Date: Mon, 6 Feb 2017 13:42:49 +0200 Subject: [PATCH] Bump to version 1.1.0 Remove middle button from tab bar due to outside touch not being recognized Update example to include a "real" middle button that supports full touch Make `commonInit` open function --- FlexTabBar.podspec | 2 +- .../project.pbxproj | 4 ++ .../ViewController.swift | 67 ++++++++++++------- WKTabBarController/WKTabBarController.swift | 2 +- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/FlexTabBar.podspec b/FlexTabBar.podspec index e914f4d..95cee92 100644 --- a/FlexTabBar.podspec +++ b/FlexTabBar.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "FlexTabBar" - s.version = "1.0.2" + s.version = "1.1.0" s.summary = "Flexible Tab Bar for Swift" s.homepage = "https://github.com/wonderkiln/FlexTabBar" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/WKTabBarController-Example.xcodeproj/project.pbxproj b/WKTabBarController-Example.xcodeproj/project.pbxproj index 9726db1..9d2c64c 100644 --- a/WKTabBarController-Example.xcodeproj/project.pbxproj +++ b/WKTabBarController-Example.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 3A3363301E48981700711F39 /* FlexTabBar.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 3A33632F1E48981700711F39 /* FlexTabBar.podspec */; }; 3A5FD9181D9BD5160061CC9C /* WKTabBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A5FD9171D9BD5160061CC9C /* WKTabBarItem.swift */; }; 3A5FD91A1D9BD5270061CC9C /* WKTabBarControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A5FD9191D9BD5270061CC9C /* WKTabBarControllerProtocol.swift */; }; 3A5FD91C1D9BD5380061CC9C /* WKBaseTabBarCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A5FD91B1D9BD5380061CC9C /* WKBaseTabBarCell.swift */; }; @@ -47,6 +48,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 3A33632F1E48981700711F39 /* FlexTabBar.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FlexTabBar.podspec; sourceTree = SOURCE_ROOT; }; 3A5FD9171D9BD5160061CC9C /* WKTabBarItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKTabBarItem.swift; sourceTree = ""; }; 3A5FD9191D9BD5270061CC9C /* WKTabBarControllerProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKTabBarControllerProtocol.swift; sourceTree = ""; }; 3A5FD91B1D9BD5380061CC9C /* WKBaseTabBarCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKBaseTabBarCell.swift; sourceTree = ""; }; @@ -117,6 +119,7 @@ 3A94D9231D828BB90064FE20 /* WKTabBarController */ = { isa = PBXGroup; children = ( + 3A33632F1E48981700711F39 /* FlexTabBar.podspec */, 3A5FD91B1D9BD5380061CC9C /* WKBaseTabBarCell.swift */, 3A94D92F1D828C020064FE20 /* WKTabBarController.swift */, 3A5FD9191D9BD5270061CC9C /* WKTabBarControllerProtocol.swift */, @@ -232,6 +235,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3A3363301E48981700711F39 /* FlexTabBar.podspec in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/WKTabBarController-Example/ViewController.swift b/WKTabBarController-Example/ViewController.swift index 9e3979a..41e15cd 100644 --- a/WKTabBarController-Example/ViewController.swift +++ b/WKTabBarController-Example/ViewController.swift @@ -80,7 +80,7 @@ class ViewController: WKTabBarController { tabBarItems = [ WKTabBarItem(title: "Home", image: #imageLiteral(resourceName: "ic_item"), selected: #imageLiteral(resourceName: "ic_item_sel")), WKTabBarItem(title: "Activity", image: #imageLiteral(resourceName: "ic_item"), selected: #imageLiteral(resourceName: "ic_item_sel")), - WKTabBarItem(title: "Add Procedure", image: #imageLiteral(resourceName: "ic_middle")), + WKTabBarItem(title: "Add Procedure", image: UIImage()), WKTabBarItem(title: "Review", image: #imageLiteral(resourceName: "ic_item"), selected: #imageLiteral(resourceName: "ic_item_sel")), WKTabBarItem(title: "Profile", image: #imageLiteral(resourceName: "ic_item"), selected: #imageLiteral(resourceName: "ic_item_sel")), ] @@ -89,19 +89,25 @@ class ViewController: WKTabBarController { } } + override func commonInit() { + super.commonInit() + + if !IS_IPAD() { + let middleButton = UIButton() + middleButton.setImage(#imageLiteral(resourceName: "ic_middle"), for: .normal) + middleButton.addTarget(self, action: #selector(showModalViewController), for: .touchUpInside) + view.addSubview(middleButton) + middleButton.translatesAutoresizingMaskIntoConstraints = false + middleButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true + middleButton.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + } + } + override func tabBarController(_ controller: WKTabBarController, customize cell: WKBaseTabBarCell, with item: WKTabBarItem, at index: Int) { if IS_IPAD() { if let cell = cell as? WKCustomTabBarImageLabelCell { cell.isAddButton = index == addButtonIndex } - } else { - if index == addButtonIndex { - cell.imageSize = 72.0 - cell.imageView?.transform = CGAffineTransform(translationX: 0, y: -5) - } else { - cell.imageSize = 22.0 - cell.imageView?.transform = CGAffineTransform.identity - } } } @@ -120,20 +126,40 @@ class ViewController: WKTabBarController { label.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor).isActive = true if index == addButtonIndex && !IS_IPAD() { - let button = UIButton(type: .system) - button.setTitle("Close", for: .normal) - button.addTarget(self, action: #selector(didTapCloseButton(_:)), for: .touchUpInside) - vc.view.addSubview(button) - button.translatesAutoresizingMaskIntoConstraints = false - button.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor).isActive = true - button.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor, constant: 50).isActive = true - present(vc, animated: true, completion: nil) - return nil + return nil // Empty space } return vc } + @objc private func showModalViewController() { + let vc = UIViewController() + vc.view.backgroundColor = UIColor(white: 0.95, alpha: 1.0) + + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 48) + label.textColor = UIColor(white: 0.8, alpha: 1.0) + label.text = "Modal" + + vc.view.addSubview(label) + label.translatesAutoresizingMaskIntoConstraints = false + label.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor).isActive = true + label.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor).isActive = true + + let button = UIButton(type: .system) + button.setTitle("Close", for: .normal) + button.addTarget(self, action: #selector(didTapCloseButton(_:)), for: .touchUpInside) + vc.view.addSubview(button) + button.translatesAutoresizingMaskIntoConstraints = false + button.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor).isActive = true + button.centerYAnchor.constraint(equalTo: vc.view.centerYAnchor, constant: 50).isActive = true + present(vc, animated: true, completion: nil) + } + + @objc private func didTapCloseButton(_ sender: AnyObject) { + dismiss(animated: true, completion: nil) + } + override func tabBarController(_ controller: WKTabBarController, cellNameAtIndex index: Int) -> WKTabBarCellName { if (index == addButtonIndex && IS_IPAD()) || (IS_IPAD() && IS_LANDSCAPE()) { return WKTabBarCellNameCustomImageLabel @@ -141,9 +167,4 @@ class ViewController: WKTabBarController { return WKTabBarCellNameImage } } - - func didTapCloseButton(_ sender: AnyObject) { - dismiss(animated: true, completion: nil) - } - } diff --git a/WKTabBarController/WKTabBarController.swift b/WKTabBarController/WKTabBarController.swift index 47fd846..b034ba2 100644 --- a/WKTabBarController/WKTabBarController.swift +++ b/WKTabBarController/WKTabBarController.swift @@ -62,7 +62,7 @@ open class WKTabBarController: UIViewController, WKTabBarControllerProtocol, UIC commonInit() } - func commonInit() { + open func commonInit() { container = UIView() container.backgroundColor = UIColor.clear view.addSubview(container)