Skip to content

Commit 95acbe3

Browse files
committed
Import a keyboard dismiss accessory view
1 parent 55b7172 commit 95acbe3

3 files changed

Lines changed: 117 additions & 1 deletion

File tree

ICInputAccessory.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
/* Begin PBXBuildFile section */
1010
B56BC42E1C89A7EA00C20AD6 /* ICInputAccessory.h in Headers */ = {isa = PBXBuildFile; fileRef = B56BC42D1C89A7EA00C20AD6 /* ICInputAccessory.h */; settings = {ATTRIBUTES = (Public, ); }; };
11+
B56BC4361C89A8D800C20AD6 /* ICKeyboardDismissAccessoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B56BC4351C89A8D800C20AD6 /* ICKeyboardDismissAccessoryView.swift */; };
1112
/* End PBXBuildFile section */
1213

1314
/* Begin PBXFileReference section */
1415
B56BC42A1C89A7EA00C20AD6 /* ICInputAccessory.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ICInputAccessory.framework; sourceTree = BUILT_PRODUCTS_DIR; };
15-
B56BC42D1C89A7EA00C20AD6 /* ICInputAccessory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ICInputAccessory.h; sourceTree = "<group>"; };
16+
B56BC42D1C89A7EA00C20AD6 /* ICInputAccessory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ICInputAccessory.h; path = Source/ICInputAccessory.h; sourceTree = SOURCE_ROOT; };
1617
B56BC42F1C89A7EA00C20AD6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
18+
B56BC4351C89A8D800C20AD6 /* ICKeyboardDismissAccessoryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ICKeyboardDismissAccessoryView.swift; path = Source/ICKeyboardDismissAccessoryView.swift; sourceTree = SOURCE_ROOT; };
1719
/* End PBXFileReference section */
1820

1921
/* Begin PBXFrameworksBuildPhase section */
@@ -47,6 +49,7 @@
4749
isa = PBXGroup;
4850
children = (
4951
B56BC42D1C89A7EA00C20AD6 /* ICInputAccessory.h */,
52+
B56BC4351C89A8D800C20AD6 /* ICKeyboardDismissAccessoryView.swift */,
5053
B56BC42F1C89A7EA00C20AD6 /* Info.plist */,
5154
);
5255
path = ICInputAccessory;
@@ -130,6 +133,7 @@
130133
isa = PBXSourcesBuildPhase;
131134
buildActionMask = 2147483647;
132135
files = (
136+
B56BC4361C89A8D800C20AD6 /* ICKeyboardDismissAccessoryView.swift in Sources */,
133137
);
134138
runOnlyForDeploymentPostprocessing = 0;
135139
};
@@ -228,6 +232,7 @@
228232
B56BC4331C89A7EA00C20AD6 /* Debug */ = {
229233
isa = XCBuildConfiguration;
230234
buildSettings = {
235+
CLANG_ENABLE_MODULES = YES;
231236
DEFINES_MODULE = YES;
232237
DYLIB_COMPATIBILITY_VERSION = 1;
233238
DYLIB_CURRENT_VERSION = 1;
@@ -238,12 +243,14 @@
238243
PRODUCT_BUNDLE_IDENTIFIER = com.polydice.ICInputAccessory;
239244
PRODUCT_NAME = "$(TARGET_NAME)";
240245
SKIP_INSTALL = YES;
246+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
241247
};
242248
name = Debug;
243249
};
244250
B56BC4341C89A7EA00C20AD6 /* Release */ = {
245251
isa = XCBuildConfiguration;
246252
buildSettings = {
253+
CLANG_ENABLE_MODULES = YES;
247254
DEFINES_MODULE = YES;
248255
DYLIB_COMPATIBILITY_VERSION = 1;
249256
DYLIB_CURRENT_VERSION = 1;
@@ -276,6 +283,7 @@
276283
B56BC4341C89A7EA00C20AD6 /* Release */,
277284
);
278285
defaultConfigurationIsVisible = 0;
286+
defaultConfigurationName = Release;
279287
};
280288
/* End XCConfigurationList section */
281289
};
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//
2+
// ICKeyboardDismissAccessoryView.swift
3+
// iCook
4+
//
5+
// Created by Ben on 27/08/2015.
6+
// Copyright (c) 2015 Polydice, Inc.
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+
import UIKit
28+
29+
class ICKeyboardDismissAccessoryView: UIView {
30+
31+
private(set) lazy var dismissButton: UIButton = {
32+
let _button = UIButton()
33+
_button.setImage(UIImage(named: "icook-iphone-button-hidekeyboard"), forState: .Normal)
34+
_button.backgroundColor = Constants.ButtonColor
35+
_button.exclusiveTouch = true
36+
_button.layer.cornerRadius = 4
37+
_button.layer.shouldRasterize = true
38+
_button.layer.rasterizationScale = UIScreen.mainScreen().scale
39+
return _button
40+
}()
41+
42+
// MARK: - Initialization
43+
44+
override init(frame: CGRect) {
45+
super.init(frame: frame)
46+
setUpSubviews()
47+
}
48+
49+
required init?(coder aDecoder: NSCoder) {
50+
super.init(coder: aDecoder)
51+
setUpSubviews()
52+
}
53+
54+
// MARK: - UIView
55+
56+
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
57+
for subview in subviews {
58+
if !subview.hidden && subview.alpha > 0 &&
59+
subview.userInteractionEnabled &&
60+
subview.pointInside(convertPoint(point, toView: subview), withEvent: event) {
61+
return true
62+
}
63+
}
64+
return false
65+
}
66+
67+
// MARK: - Private Methods
68+
69+
private struct Constants {
70+
static let ButtonColor = UIColor(red:0.21, green:0.2, blue:0.19, alpha:0.5)
71+
static let EdgePadding = CGFloat(7)
72+
static let InteractiveSize = CGSize(width: 44, height: 44)
73+
}
74+
75+
private func setUpSubviews() {
76+
backgroundColor = UIColor.clearColor()
77+
78+
addSubview(dismissButton)
79+
dismissButton.translatesAutoresizingMaskIntoConstraints = false
80+
81+
let views = ["button": dismissButton]
82+
let metrics = [
83+
"width": Constants.InteractiveSize.width,
84+
"height": Constants.InteractiveSize.height,
85+
"padding": Constants.EdgePadding
86+
]
87+
88+
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
89+
"H:[button(width)]-(padding)-|",
90+
options: [],
91+
metrics: metrics,
92+
views: views
93+
))
94+
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
95+
"V:[button(height)]-(padding)-|",
96+
options: [],
97+
metrics: metrics,
98+
views: views
99+
))
100+
}
101+
102+
// MARK: - Public Methods
103+
104+
class func requiredHeight() -> CGFloat {
105+
return Constants.InteractiveSize.height + Constants.EdgePadding * 2
106+
}
107+
108+
}

0 commit comments

Comments
 (0)