Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit aa2ebea

Browse files
Timmi TrinksDominik Hadl
authored andcommitted
- Swift version of KeyboardHelper
- some tests
1 parent 99743f2 commit aa2ebea

File tree

11 files changed

+261
-189
lines changed

11 files changed

+261
-189
lines changed

KeyboardHelper.xcodeproj/project.pbxproj

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
275BCA7B1C57C9F800FF3647 /* KeyboardHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 275BCA7A1C57C9F800FF3647 /* KeyboardHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
1110
275BCA821C57C9F800FF3647 /* KeyboardHelper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 275BCA771C57C9F800FF3647 /* KeyboardHelper.framework */; };
12-
275BCA871C57C9F800FF3647 /* KeyboardHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 275BCA861C57C9F800FF3647 /* KeyboardHelperTests.swift */; };
13-
275BCA931C57CA0000FF3647 /* NOKeyboardHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 275BCA911C57CA0000FF3647 /* NOKeyboardHelper.h */; };
14-
275BCA941C57CA0000FF3647 /* NOKeyboardHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 275BCA921C57CA0000FF3647 /* NOKeyboardHelper.m */; };
11+
82B793861C6495D000AB8A48 /* KeyboardAppearanceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82B793811C6495D000AB8A48 /* KeyboardAppearanceInfo.swift */; };
12+
82B793871C6495D000AB8A48 /* KeyboardHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82B793821C6495D000AB8A48 /* KeyboardHelper.swift */; };
13+
82B793891C6495D000AB8A48 /* KeyboardHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B793851C6495D000AB8A48 /* KeyboardHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
14+
82B793941C64996E00AB8A48 /* KeyboardAppearanceInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82B793911C64996E00AB8A48 /* KeyboardAppearanceInfoTests.swift */; };
15+
82B793951C64996E00AB8A48 /* KeyboardHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82B793921C64996E00AB8A48 /* KeyboardHelperTests.swift */; };
1516
/* End PBXBuildFile section */
1617

1718
/* Begin PBXContainerItemProxy section */
@@ -26,13 +27,14 @@
2627

2728
/* Begin PBXFileReference section */
2829
275BCA771C57C9F800FF3647 /* KeyboardHelper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KeyboardHelper.framework; sourceTree = BUILT_PRODUCTS_DIR; };
29-
275BCA7A1C57C9F800FF3647 /* KeyboardHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyboardHelper.h; sourceTree = "<group>"; };
30-
275BCA7C1C57C9F800FF3647 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3130
275BCA811C57C9F800FF3647 /* KeyboardHelperTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KeyboardHelperTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
32-
275BCA861C57C9F800FF3647 /* KeyboardHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardHelperTests.swift; sourceTree = "<group>"; };
33-
275BCA881C57C9F800FF3647 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
34-
275BCA911C57CA0000FF3647 /* NOKeyboardHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NOKeyboardHelper.h; sourceTree = "<group>"; };
35-
275BCA921C57CA0000FF3647 /* NOKeyboardHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NOKeyboardHelper.m; sourceTree = "<group>"; };
31+
82B793811C6495D000AB8A48 /* KeyboardAppearanceInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardAppearanceInfo.swift; sourceTree = "<group>"; };
32+
82B793821C6495D000AB8A48 /* KeyboardHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardHelper.swift; sourceTree = "<group>"; };
33+
82B793841C6495D000AB8A48 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
34+
82B793851C6495D000AB8A48 /* KeyboardHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyboardHelper.h; sourceTree = "<group>"; };
35+
82B7938F1C64996E00AB8A48 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
36+
82B793911C64996E00AB8A48 /* KeyboardAppearanceInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardAppearanceInfoTests.swift; sourceTree = "<group>"; };
37+
82B793921C64996E00AB8A48 /* KeyboardHelperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardHelperTests.swift; sourceTree = "<group>"; };
3638
/* End PBXFileReference section */
3739

3840
/* Begin PBXFrameworksBuildPhase section */
@@ -75,32 +77,64 @@
7577
275BCA791C57C9F800FF3647 /* KeyboardHelper */ = {
7678
isa = PBXGroup;
7779
children = (
78-
275BCA911C57CA0000FF3647 /* NOKeyboardHelper.h */,
79-
275BCA921C57CA0000FF3647 /* NOKeyboardHelper.m */,
80-
275BCA7A1C57C9F800FF3647 /* KeyboardHelper.h */,
81-
275BCA7C1C57C9F800FF3647 /* Info.plist */,
80+
82B793801C6495D000AB8A48 /* Classes */,
81+
82B793831C6495D000AB8A48 /* Supporting Files */,
8282
);
8383
path = KeyboardHelper;
8484
sourceTree = "<group>";
8585
};
8686
275BCA851C57C9F800FF3647 /* KeyboardHelperTests */ = {
8787
isa = PBXGroup;
8888
children = (
89-
275BCA861C57C9F800FF3647 /* KeyboardHelperTests.swift */,
90-
275BCA881C57C9F800FF3647 /* Info.plist */,
89+
82B793901C64996E00AB8A48 /* Tests */,
90+
82B7938E1C64996E00AB8A48 /* Supporting Files */,
9191
);
9292
path = KeyboardHelperTests;
9393
sourceTree = "<group>";
9494
};
95+
82B793801C6495D000AB8A48 /* Classes */ = {
96+
isa = PBXGroup;
97+
children = (
98+
82B793811C6495D000AB8A48 /* KeyboardAppearanceInfo.swift */,
99+
82B793821C6495D000AB8A48 /* KeyboardHelper.swift */,
100+
);
101+
path = Classes;
102+
sourceTree = "<group>";
103+
};
104+
82B793831C6495D000AB8A48 /* Supporting Files */ = {
105+
isa = PBXGroup;
106+
children = (
107+
82B793841C6495D000AB8A48 /* Info.plist */,
108+
82B793851C6495D000AB8A48 /* KeyboardHelper.h */,
109+
);
110+
path = "Supporting Files";
111+
sourceTree = "<group>";
112+
};
113+
82B7938E1C64996E00AB8A48 /* Supporting Files */ = {
114+
isa = PBXGroup;
115+
children = (
116+
82B7938F1C64996E00AB8A48 /* Info.plist */,
117+
);
118+
path = "Supporting Files";
119+
sourceTree = "<group>";
120+
};
121+
82B793901C64996E00AB8A48 /* Tests */ = {
122+
isa = PBXGroup;
123+
children = (
124+
82B793911C64996E00AB8A48 /* KeyboardAppearanceInfoTests.swift */,
125+
82B793921C64996E00AB8A48 /* KeyboardHelperTests.swift */,
126+
);
127+
path = Tests;
128+
sourceTree = "<group>";
129+
};
95130
/* End PBXGroup section */
96131

97132
/* Begin PBXHeadersBuildPhase section */
98133
275BCA741C57C9F800FF3647 /* Headers */ = {
99134
isa = PBXHeadersBuildPhase;
100135
buildActionMask = 2147483647;
101136
files = (
102-
275BCA931C57CA0000FF3647 /* NOKeyboardHelper.h in Headers */,
103-
275BCA7B1C57C9F800FF3647 /* KeyboardHelper.h in Headers */,
137+
82B793891C6495D000AB8A48 /* KeyboardHelper.h in Headers */,
104138
);
105139
runOnlyForDeploymentPostprocessing = 0;
106140
};
@@ -201,15 +235,17 @@
201235
isa = PBXSourcesBuildPhase;
202236
buildActionMask = 2147483647;
203237
files = (
204-
275BCA941C57CA0000FF3647 /* NOKeyboardHelper.m in Sources */,
238+
82B793871C6495D000AB8A48 /* KeyboardHelper.swift in Sources */,
239+
82B793861C6495D000AB8A48 /* KeyboardAppearanceInfo.swift in Sources */,
205240
);
206241
runOnlyForDeploymentPostprocessing = 0;
207242
};
208243
275BCA7D1C57C9F800FF3647 /* Sources */ = {
209244
isa = PBXSourcesBuildPhase;
210245
buildActionMask = 2147483647;
211246
files = (
212-
275BCA871C57C9F800FF3647 /* KeyboardHelperTests.swift in Sources */,
247+
82B793951C64996E00AB8A48 /* KeyboardHelperTests.swift in Sources */,
248+
82B793941C64996E00AB8A48 /* KeyboardAppearanceInfoTests.swift in Sources */,
213249
);
214250
runOnlyForDeploymentPostprocessing = 0;
215251
};
@@ -241,7 +277,6 @@
241277
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
242278
CLANG_WARN_UNREACHABLE_CODE = YES;
243279
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
244-
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
245280
COPY_PHASE_STRIP = NO;
246281
CURRENT_PROJECT_VERSION = 1;
247282
DEBUG_INFORMATION_FORMAT = dwarf;
@@ -261,7 +296,7 @@
261296
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
262297
GCC_WARN_UNUSED_FUNCTION = YES;
263298
GCC_WARN_UNUSED_VARIABLE = YES;
264-
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
299+
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
265300
MTL_ENABLE_DEBUG_INFO = YES;
266301
ONLY_ACTIVE_ARCH = YES;
267302
SDKROOT = iphoneos;
@@ -289,7 +324,6 @@
289324
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
290325
CLANG_WARN_UNREACHABLE_CODE = YES;
291326
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
292-
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
293327
COPY_PHASE_STRIP = NO;
294328
CURRENT_PROJECT_VERSION = 1;
295329
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@@ -303,7 +337,7 @@
303337
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
304338
GCC_WARN_UNUSED_FUNCTION = YES;
305339
GCC_WARN_UNUSED_VARIABLE = YES;
306-
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
340+
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
307341
MTL_ENABLE_DEBUG_INFO = NO;
308342
SDKROOT = iphoneos;
309343
TARGETED_DEVICE_FAMILY = "1,2";
@@ -320,12 +354,15 @@
320354
DYLIB_COMPATIBILITY_VERSION = 1;
321355
DYLIB_CURRENT_VERSION = 1;
322356
DYLIB_INSTALL_NAME_BASE = "@rpath";
323-
INFOPLIST_FILE = KeyboardHelper/Info.plist;
357+
INFOPLIST_FILE = "$(SRCROOT)/KeyboardHelper/Supporting Files/Info.plist";
324358
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
359+
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
325360
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
326361
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelper;
327362
PRODUCT_NAME = "$(TARGET_NAME)";
328363
SKIP_INSTALL = YES;
364+
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
365+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
329366
};
330367
name = Debug;
331368
};
@@ -336,19 +373,21 @@
336373
DYLIB_COMPATIBILITY_VERSION = 1;
337374
DYLIB_CURRENT_VERSION = 1;
338375
DYLIB_INSTALL_NAME_BASE = "@rpath";
339-
INFOPLIST_FILE = KeyboardHelper/Info.plist;
376+
INFOPLIST_FILE = "$(SRCROOT)/KeyboardHelper/Supporting Files/Info.plist";
340377
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
378+
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
341379
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
342380
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelper;
343381
PRODUCT_NAME = "$(TARGET_NAME)";
344382
SKIP_INSTALL = YES;
383+
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
345384
};
346385
name = Release;
347386
};
348387
275BCA8F1C57C9F800FF3647 /* Debug */ = {
349388
isa = XCBuildConfiguration;
350389
buildSettings = {
351-
INFOPLIST_FILE = KeyboardHelperTests/Info.plist;
390+
INFOPLIST_FILE = "KeyboardHelperTests/Supporting Files/Info.plist";
352391
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
353392
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
354393
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -358,7 +397,7 @@
358397
275BCA901C57C9F800FF3647 /* Release */ = {
359398
isa = XCBuildConfiguration;
360399
buildSettings = {
361-
INFOPLIST_FILE = KeyboardHelperTests/Info.plist;
400+
INFOPLIST_FILE = "KeyboardHelperTests/Supporting Files/Info.plist";
362401
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
363402
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
364403
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -384,6 +423,7 @@
384423
275BCA8D1C57C9F800FF3647 /* Release */,
385424
);
386425
defaultConfigurationIsVisible = 0;
426+
defaultConfigurationName = Release;
387427
};
388428
275BCA8E1C57C9F800FF3647 /* Build configuration list for PBXNativeTarget "KeyboardHelperTests" */ = {
389429
isa = XCConfigurationList;
@@ -392,6 +432,7 @@
392432
275BCA901C57C9F800FF3647 /* Release */,
393433
);
394434
defaultConfigurationIsVisible = 0;
435+
defaultConfigurationName = Release;
395436
};
396437
/* End XCConfigurationList section */
397438
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// KeyboardAppearanceInfo.swift
3+
// KeyboardHelper
4+
//
5+
// Created by Timmi Trinks on 04/02/16.
6+
// Copyright © 2016 Nodes. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
public struct KeyboardAppearanceInfo {
13+
14+
public let notification: NSNotification
15+
public let userInfo: [NSObject: AnyObject]
16+
17+
public init(notification: NSNotification) {
18+
self.notification = notification
19+
self.userInfo = notification.userInfo ?? [:]
20+
}
21+
22+
/**
23+
Getter for the UIKeyboard Info
24+
*/
25+
public var beginFrame: CGRect {
26+
return userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue ?? CGRectZero
27+
}
28+
29+
public var endFrame: CGRect {
30+
return userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue ?? CGRectZero
31+
}
32+
33+
public var belongsToCurrentApp: Bool {
34+
if #available(iOS 9.0, *) {
35+
return userInfo[UIKeyboardIsLocalUserInfoKey]?.boolValue ?? true
36+
} else {
37+
return true
38+
}
39+
}
40+
41+
public var animationDuration: Double {
42+
return userInfo[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue ?? 0.25
43+
}
44+
45+
public var animationCurve: UIViewAnimationCurve {
46+
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .EaseInOut }
47+
return UIViewAnimationCurve(rawValue: value) ?? .EaseInOut
48+
}
49+
50+
public var animationOptions: UIViewAnimationOptions {
51+
return UIViewAnimationOptions(rawValue: UInt(animationCurve.rawValue << 16))
52+
}
53+
54+
func animateAlong(animationBlock: () -> Void, completion: (finished: Bool) -> Void) {
55+
UIView.animateWithDuration(
56+
animationDuration,
57+
delay: 0.0,
58+
options: animationOptions,
59+
animations: animationBlock,
60+
completion: completion
61+
)}
62+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// KeyboardHelper.swift
3+
// KeyboardHelper
4+
//
5+
// Created by Timmi Trinks on 27/01/16.
6+
// Copyright © 2016 Nodes. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
public protocol KeyboardNotificationDelegate {
13+
func keyboardWillAppear(info: KeyboardAppearanceInfo)
14+
func keyboardWillDisappear(info: KeyboardAppearanceInfo)
15+
}
16+
17+
public class KeyboardHelper {
18+
19+
public let delegate: KeyboardNotificationDelegate?
20+
21+
required public init(delegate: KeyboardNotificationDelegate) {
22+
self.delegate = delegate
23+
24+
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillAppear:", name: UIKeyboardWillShowNotification, object: nil)
25+
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillDisappear:", name: UIKeyboardWillHideNotification, object: nil)
26+
}
27+
28+
private init() {
29+
delegate = nil
30+
}
31+
32+
public func keyboardWillAppear(note: NSNotification) {
33+
let info = KeyboardAppearanceInfo(notification: note)
34+
self.delegate?.keyboardWillAppear(info)
35+
}
36+
37+
public func keyboardWillDisappear(note: NSNotification) {
38+
let info = KeyboardAppearanceInfo(notification: note)
39+
self.delegate?.keyboardWillDisappear(info)
40+
}
41+
42+
deinit {
43+
NSNotificationCenter.defaultCenter().removeObserver(self)
44+
}
45+
}

KeyboardHelper/NOKeyboardHelper.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)