Skip to content

Commit 1d1e9ea

Browse files
author
Richard Piazza
committed
Reset podspec source files.
1 parent ebb6cc2 commit 1d1e9ea

File tree

3 files changed

+192
-5
lines changed

3 files changed

+192
-5
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// UIPickerView.swift
4+
//
5+
// Copyright (c) 2016 Richard Piazza
6+
// https://github.com/richardpiazza/CodeQuickKit
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in all
16+
// copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
// SOFTWARE.
25+
//
26+
//===----------------------------------------------------------------------===//
27+
28+
import UIKit
29+
30+
extension UIPickerView {
31+
32+
private class Manager: PickerViewControllerDelegate {
33+
var pickerViewController: PickerViewController = PickerViewController()
34+
var presentingView: UIView?
35+
36+
func offScreenFrame() -> CGRect {
37+
if let view = presentingView {
38+
return CGRect(x: view.bounds.origin.x, y: view.bounds.size.height + PickerViewController.defaultViewHeight, width: view.bounds.size.width, height: PickerViewController.defaultViewHeight)
39+
} else {
40+
return CGRect(x: 0.0, y: -PickerViewController.defaultViewHeight, width: PickerViewController.defaultViewWidth, height: PickerViewController.defaultViewHeight)
41+
}
42+
}
43+
44+
func onScreenFrame() -> CGRect {
45+
if let view = presentingView {
46+
return CGRect(x: view.bounds.origin.x, y: view.bounds.size.height - PickerViewController.defaultViewHeight, width: view.bounds.size.width, height: PickerViewController.defaultViewHeight)
47+
} else {
48+
return CGRect(x: 0.0, y: 0.0, width: PickerViewController.defaultViewWidth, height: PickerViewController.defaultViewHeight)
49+
}
50+
}
51+
52+
func present(fromView: UIView, withTitle title: String?, configuration: UIPickerViewConfigurationBlock) {
53+
presentingView = fromView
54+
pickerViewController.toolbarTitle.title = title ?? ""
55+
configuration(pickerView: pickerViewController.picker)
56+
57+
pickerViewController.view.frame = offScreenFrame()
58+
fromView.addSubview(pickerViewController.view)
59+
UIView.animateWithDuration(0.5) {
60+
self.pickerViewController.view.frame = self.onScreenFrame()
61+
}
62+
63+
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(Manager.uiKeyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
64+
}
65+
66+
func resign() {
67+
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
68+
69+
UIView.animateWithDuration(0.4, animations: {
70+
self.pickerViewController.view.frame = self.offScreenFrame()
71+
}) { (complete: Bool) in
72+
self.pickerViewController.view.removeFromSuperview()
73+
self.presentingView = nil
74+
}
75+
}
76+
77+
@objc private func uiKeyboardWillShow(notification: NSNotification) {
78+
79+
}
80+
81+
private func didTapCancelOnPickerViewController(pickerViewController: PickerViewController) {
82+
resign()
83+
}
84+
85+
private func didTapDoneOnPickerViewController(pickerViewController: PickerViewController) {
86+
resign()
87+
}
88+
}
89+
90+
private static var manager = Manager()
91+
92+
static func present(fromView: UIView, withTitle title: String?, configuration: UIPickerViewConfigurationBlock) {
93+
manager.present(fromView, withTitle: title, configuration: configuration)
94+
}
95+
96+
static func present(fromView: UIView, withTitle title: String?, options: [String], selectedIndex: Int?, selectionHandler: UIPickerViewSelectionHandler) {
97+
98+
}
99+
100+
static func resign() {
101+
manager.resign()
102+
}
103+
}
104+
105+
public typealias UIPickerViewConfigurationBlock = (pickerView: UIPickerView) -> Void
106+
public typealias UIPickerViewSelectionHandler = (pickerView: UIPickerView, selectedItem: String, index: Int) -> Void
107+
108+
internal protocol PickerViewControllerDelegate {
109+
func didTapCancelOnPickerViewController(pickerViewController: PickerViewController)
110+
func didTapDoneOnPickerViewController(pickerViewController: PickerViewController)
111+
}
112+
113+
internal class PickerViewController: UIViewController {
114+
static let defaultToolbarHeight: CGFloat = 44.0
115+
static let defaultPickerHeight: CGFloat = 216.0
116+
static let defaultViewHeight: CGFloat = 260.0
117+
static let defaultViewWidth: CGFloat = 320.0
118+
119+
private var flex = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil)
120+
private var toolbarTitle = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
121+
private lazy var cancel: UIBarButtonItem = {
122+
[unowned self] in
123+
return UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: #selector(PickerViewController.didTapDone(_:)))
124+
}()
125+
private lazy var done: UIBarButtonItem = {
126+
[unowned self] in
127+
return UIBarButtonItem(barButtonSystemItem: .Done, target: self, action: #selector(PickerViewController.didTapDone(_:)))
128+
}()
129+
private lazy var fixed: UIBarButtonItem = {
130+
let barButton = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
131+
barButton.width = 8.0
132+
return barButton
133+
}()
134+
135+
lazy var picker: UIPickerView = {
136+
let view = UIPickerView(frame: CGRect(x: 0, y: PickerViewController.defaultToolbarHeight, width: PickerViewController.defaultViewWidth, height: PickerViewController.defaultPickerHeight))
137+
view.translatesAutoresizingMaskIntoConstraints = false
138+
return view
139+
}()
140+
141+
var delegate: PickerViewControllerDelegate?
142+
143+
override func loadView() {
144+
self.view = UIView(frame: CGRect(x: 0, y: 0, width: PickerViewController.defaultViewWidth, height: PickerViewController.defaultViewHeight))
145+
view.backgroundColor = UIColor.clearColor()
146+
147+
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .ExtraLight))
148+
blurView.translatesAutoresizingMaskIntoConstraints = false
149+
blurView.frame = view.bounds
150+
view.addSubview(blurView)
151+
152+
view.addConstraint(NSLayoutConstraint(item: blurView, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: 0.0))
153+
view.addConstraint(NSLayoutConstraint(item: blurView, attribute: .Bottom, relatedBy: .Equal, toItem: view, attribute: .Bottom, multiplier: 1.0, constant: 0.0))
154+
view.addConstraint(NSLayoutConstraint(item: blurView, attribute: .Left, relatedBy: .Equal, toItem: view, attribute: .Left, multiplier: 1.0, constant: 0.0))
155+
view.addConstraint(NSLayoutConstraint(item: blurView, attribute: .Right, relatedBy: .Equal, toItem: view, attribute: .Right, multiplier: 1.0, constant: 0.0))
156+
157+
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: PickerViewController.defaultViewWidth, height: PickerViewController.defaultToolbarHeight))
158+
toolbar.setItems([fixed, cancel, flex, toolbarTitle, flex, done, fixed], animated: false)
159+
toolbar.translatesAutoresizingMaskIntoConstraints = false
160+
view.addSubview(toolbar)
161+
162+
toolbar.addConstraint(NSLayoutConstraint(item: toolbar, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: PickerViewController.defaultToolbarHeight))
163+
view.addConstraint(NSLayoutConstraint(item: toolbar, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: 0.0))
164+
view.addConstraint(NSLayoutConstraint(item: toolbar, attribute: .Left, relatedBy: .Equal, toItem: view, attribute: .Left, multiplier: 1.0, constant: 0.0))
165+
view.addConstraint(NSLayoutConstraint(item: toolbar, attribute: .Right, relatedBy: .Equal, toItem: view, attribute: .Right, multiplier: 1.0, constant: 0.0))
166+
167+
view.addSubview(picker)
168+
picker.addConstraint(NSLayoutConstraint(item: picker, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: PickerViewController.defaultPickerHeight))
169+
view.addConstraint(NSLayoutConstraint(item: picker, attribute: .Top, relatedBy: .Equal, toItem: toolbar, attribute: .Bottom, multiplier: 1.0, constant: 0.0))
170+
view.addConstraint(NSLayoutConstraint(item: picker, attribute: .Left, relatedBy: .Equal, toItem: view, attribute: .Left, multiplier: 1.0, constant: 0.0))
171+
view.addConstraint(NSLayoutConstraint(item: picker, attribute: .Right, relatedBy: .Equal, toItem: view, attribute: .Right, multiplier: 1.0, constant: 0.0))
172+
}
173+
174+
@objc func didTapCancel(sender: UIBarButtonItem) {
175+
if let delegate = self.delegate {
176+
delegate.didTapCancelOnPickerViewController(self)
177+
}
178+
}
179+
180+
@objc func didTapDone(sender: UIBarButtonItem) {
181+
if let delegate = self.delegate {
182+
delegate.didTapDoneOnPickerViewController(self)
183+
}
184+
}
185+
}

CodeQuickKit.podspec

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "CodeQuickKit"
11-
s.version = "2.0.0"
11+
s.version = "2.0.1"
1212
s.summary = "An iOS Library simplifying some everyday tasks."
1313
s.description = <<-DESC
1414
CodeQuickKit is a collection of Swift extensions and classes designed to
@@ -26,9 +26,7 @@ Pod::Spec.new do |s|
2626
s.platform = :ios, '8.0'
2727
s.requires_arc = true
2828

29-
s.source_files = 'CodeQuickKit-ObjC/*'
30-
# s.resource_bundles = { 'CodeQuickKit' => ['Pod/Assets/*.png'] }
31-
32-
s.public_header_files = 'CodeQuickKit-ObjC/*.h'
29+
s.source_files = 'CodeQuickKit-Swift/*'
30+
# s.public_header_files = 'CodeQuickKit-Swift/*.h'
3331
s.frameworks = 'UIKit', 'CoreData'
3432
end

CodeQuickKit/CodeQuickKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
E166D3381CA5294200EF5B06 /* UIPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E166D3371CA5294200EF5B06 /* UIPickerView.swift */; };
1011
E18740681C8D048500A7761C /* SerializableManagedObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18740671C8D048500A7761C /* SerializableManagedObject.swift */; };
1112
E187406A1C8D56DB00A7761C /* NSMetadataQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = E18740691C8D56DB00A7761C /* NSMetadataQuery.swift */; };
1213
E187406C1C8D7C8500A7761C /* CoreDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E187406B1C8D7C8500A7761C /* CoreDataTests.swift */; };
@@ -58,6 +59,7 @@
5859
E121CAAE1C85AD7B0003C1B6 /* Serializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Serializer.swift; sourceTree = "<group>"; };
5960
E121CAB01C85AD7B0003C1B6 /* UIAlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIAlertController.swift; sourceTree = "<group>"; };
6061
E121CAB21C85AD7B0003C1B6 /* WebAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebAPI.swift; sourceTree = "<group>"; };
62+
E166D3371CA5294200EF5B06 /* UIPickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIPickerView.swift; sourceTree = "<group>"; };
6163
E18740671C8D048500A7761C /* SerializableManagedObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializableManagedObject.swift; sourceTree = "<group>"; };
6264
E18740691C8D56DB00A7761C /* NSMetadataQuery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSMetadataQuery.swift; sourceTree = "<group>"; };
6365
E187406B1C8D7C8500A7761C /* CoreDataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataTests.swift; sourceTree = "<group>"; };
@@ -158,6 +160,7 @@
158160
E1E54C401C8865BA003F12B3 /* SerializableObject.swift */,
159161
E1E54C3A1C880839003F12B3 /* Storyboarded.swift */,
160162
E121CAB01C85AD7B0003C1B6 /* UIAlertController.swift */,
163+
E166D3371CA5294200EF5B06 /* UIPickerView.swift */,
161164
E121CAB21C85AD7B0003C1B6 /* WebAPI.swift */,
162165
);
163166
name = "CodeQuickKit-Swift";
@@ -366,6 +369,7 @@
366369
buildActionMask = 2147483647;
367370
files = (
368371
E1E54C2F1C87F0D9003F12B3 /* NSDate.swift in Sources */,
372+
E166D3381CA5294200EF5B06 /* UIPickerView.swift in Sources */,
369373
E1E54C331C87F0D9003F12B3 /* NSNumberFormatter.swift in Sources */,
370374
E1E54C371C87F0D9003F12B3 /* UIAlertController.swift in Sources */,
371375
E1E54C3D1C88627D003F12B3 /* Serializable.swift in Sources */,

0 commit comments

Comments
 (0)