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

Commit 8926903

Browse files
Timmi TrinksDominik Hadl
Timmi Trinks
authored and
Dominik Hadl
committed
- documentation for KeyboardHelper, KeyboardAppearanceInfo and KeyboardAppearanceInfoTests
- test for animateAlong
1 parent aa2ebea commit 8926903

File tree

4 files changed

+177
-14
lines changed

4 files changed

+177
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0720"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "275BCA761C57C9F800FF3647"
18+
BuildableName = "KeyboardHelper.framework"
19+
BlueprintName = "KeyboardHelper"
20+
ReferencedContainer = "container:KeyboardHelper.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "275BCA801C57C9F800FF3647"
36+
BuildableName = "KeyboardHelperTests.xctest"
37+
BlueprintName = "KeyboardHelperTests"
38+
ReferencedContainer = "container:KeyboardHelper.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "275BCA761C57C9F800FF3647"
46+
BuildableName = "KeyboardHelper.framework"
47+
BlueprintName = "KeyboardHelper"
48+
ReferencedContainer = "container:KeyboardHelper.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
<AdditionalOptions>
52+
</AdditionalOptions>
53+
</TestAction>
54+
<LaunchAction
55+
buildConfiguration = "Debug"
56+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
57+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
58+
launchStyle = "0"
59+
useCustomWorkingDirectory = "NO"
60+
ignoresPersistentStateOnLaunch = "NO"
61+
debugDocumentVersioning = "YES"
62+
debugServiceExtension = "internal"
63+
allowLocationSimulation = "YES">
64+
<MacroExpansion>
65+
<BuildableReference
66+
BuildableIdentifier = "primary"
67+
BlueprintIdentifier = "275BCA761C57C9F800FF3647"
68+
BuildableName = "KeyboardHelper.framework"
69+
BlueprintName = "KeyboardHelper"
70+
ReferencedContainer = "container:KeyboardHelper.xcodeproj">
71+
</BuildableReference>
72+
</MacroExpansion>
73+
<AdditionalOptions>
74+
</AdditionalOptions>
75+
</LaunchAction>
76+
<ProfileAction
77+
buildConfiguration = "Release"
78+
shouldUseLaunchSchemeArgsEnv = "YES"
79+
savedToolIdentifier = ""
80+
useCustomWorkingDirectory = "NO"
81+
debugDocumentVersioning = "YES">
82+
<MacroExpansion>
83+
<BuildableReference
84+
BuildableIdentifier = "primary"
85+
BlueprintIdentifier = "275BCA761C57C9F800FF3647"
86+
BuildableName = "KeyboardHelper.framework"
87+
BlueprintName = "KeyboardHelper"
88+
ReferencedContainer = "container:KeyboardHelper.xcodeproj">
89+
</BuildableReference>
90+
</MacroExpansion>
91+
</ProfileAction>
92+
<AnalyzeAction
93+
buildConfiguration = "Debug">
94+
</AnalyzeAction>
95+
<ArchiveAction
96+
buildConfiguration = "Release"
97+
revealArchiveInOrganizer = "YES">
98+
</ArchiveAction>
99+
</Scheme>

KeyboardHelper/Classes/KeyboardAppearanceInfo.swift

+35-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import Foundation
1010
import UIKit
1111

12+
/**
13+
A struct holding all keyboard view information when it's being shown or hidden.
14+
*/
1215
public struct KeyboardAppearanceInfo {
1316

1417
public let notification: NSNotification
@@ -20,16 +23,26 @@ public struct KeyboardAppearanceInfo {
2023
}
2124

2225
/**
23-
Getter for the UIKeyboard Info
26+
Getter for the UIKeyboard frame begin infokey.
27+
Return a `CGRect` or `CGRectZero`.
2428
*/
2529
public var beginFrame: CGRect {
2630
return userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue ?? CGRectZero
2731
}
2832

33+
/**
34+
Getter for the UIKeyboard frame end infokey.
35+
Return a `CGRect` or `CGRectZero`.
36+
*/
2937
public var endFrame: CGRect {
3038
return userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue ?? CGRectZero
3139
}
3240

41+
/**
42+
Getter for the UIKeyboard info if the keyboard is in the current app.
43+
That variable will help to keep track of which app uses the keyboard at the moment.
44+
If it is the current app it is true, if not it is false.
45+
*/
3346
public var belongsToCurrentApp: Bool {
3447
if #available(iOS 9.0, *) {
3548
return userInfo[UIKeyboardIsLocalUserInfoKey]?.boolValue ?? true
@@ -38,20 +51,40 @@ public struct KeyboardAppearanceInfo {
3851
}
3952
}
4053

54+
/**
55+
Getter for the duration of the keyboard appear/disappear animation.
56+
By default: `0.25`.
57+
*/
4158
public var animationDuration: Double {
4259
return userInfo[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue ?? 0.25
4360
}
4461

62+
/**
63+
Getter for the animation curve.
64+
By default: `EaseInOut`.
65+
*/
4566
public var animationCurve: UIViewAnimationCurve {
4667
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .EaseInOut }
4768
return UIViewAnimationCurve(rawValue: value) ?? .EaseInOut
4869
}
4970

71+
/**
72+
Getter for the animation option.
73+
That variable will help to keep track of the keyboard appearence.
74+
*/
5075
public var animationOptions: UIViewAnimationOptions {
5176
return UIViewAnimationOptions(rawValue: UInt(animationCurve.rawValue << 16))
5277
}
5378

54-
func animateAlong(animationBlock: () -> Void, completion: (finished: Bool) -> Void) {
79+
/**
80+
Animate a `UView` while the keyboard appears and check if animation is finished.
81+
If finished do completion.
82+
83+
Parameters:
84+
- animationBlock: Animation that should happen.
85+
- completion: Function that happens after the animation is finished.
86+
*/
87+
public func animateAlong(animationBlock: () -> Void, completion: (finished: Bool) -> Void) {
5588
UIView.animateWithDuration(
5689
animationDuration,
5790
delay: 0.0,

KeyboardHelper/Classes/KeyboardHelper.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,39 @@
99
import Foundation
1010
import UIKit
1111

12+
/**
13+
Protocol `KeyboardNotificationDelegate` requires two functions.
14+
Function `keyboardWillAppear` and `keyboardWillDisappear` with parameter `info` struct `KeyboardAppearanceInfo`.
15+
*/
1216
public protocol KeyboardNotificationDelegate {
17+
18+
/**
19+
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will appaear.
20+
- Parameter info: Struct `KeyboardAppearanceInfo`.
21+
*/
1322
func keyboardWillAppear(info: KeyboardAppearanceInfo)
23+
24+
/**
25+
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will disappaear.
26+
- Parameter info: Struct `KeyboardAppearanceInfo`.
27+
*/
1428
func keyboardWillDisappear(info: KeyboardAppearanceInfo)
1529
}
1630

31+
/**
32+
Useful helper to keep track of keyboard changes.
33+
*/
1734
public class KeyboardHelper {
1835

36+
/**
37+
Delegate that conforms with the `KeyboardNotificationDelegate`.
38+
*/
1939
public let delegate: KeyboardNotificationDelegate?
2040

41+
/**
42+
Initialize the `delegate` and add the two observer for `keyboardWillAppear` and `keyboardWillDisappear`.
43+
Observers are nessecary for tracking the `UIKeyboardWillShowNotification` and `UIKeyboardWillHideNotification`, so the function that are connectet are getting fired.
44+
*/
2145
required public init(delegate: KeyboardNotificationDelegate) {
2246
self.delegate = delegate
2347

@@ -29,12 +53,12 @@ public class KeyboardHelper {
2953
delegate = nil
3054
}
3155

32-
public func keyboardWillAppear(note: NSNotification) {
56+
private func keyboardWillAppear(note: NSNotification) {
3357
let info = KeyboardAppearanceInfo(notification: note)
3458
self.delegate?.keyboardWillAppear(info)
3559
}
3660

37-
public func keyboardWillDisappear(note: NSNotification) {
61+
private func keyboardWillDisappear(note: NSNotification) {
3862
let info = KeyboardAppearanceInfo(notification: note)
3963
self.delegate?.keyboardWillDisappear(info)
4064
}

KeyboardHelperTests/Tests/KeyboardAppearanceInfoTests.swift

+17-10
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ class KeyboardAppearanceInfoTests: XCTestCase {
1515

1616
override func setUp() {
1717
super.setUp()
18-
19-
var animationCurve = UIViewAnimationCurve.EaseInOut
20-
NSNumber(integer: 7).getValue(&animationCurve)
2118

2219
// Create test info
2320
var testUserInfo: [String: AnyObject] = [
2421
UIKeyboardFrameBeginUserInfoKey: NSValue(CGRect: CGRect(x: 100, y: 100, width: 100, height: 100)),
2522
UIKeyboardFrameEndUserInfoKey: NSValue(CGRect: CGRect(x: 200, y: 200, width: 200, height: 200)),
26-
UIKeyboardAnimationDurationUserInfoKey: Double(3),
27-
UIKeyboardAnimationCurveUserInfoKey: animationCurve.rawValue,
23+
UIKeyboardAnimationDurationUserInfoKey: 3.0,
24+
UIKeyboardAnimationCurveUserInfoKey: UIViewAnimationCurve.EaseOut.rawValue,
2825
]
2926

3027
if #available(iOS 9.0, *) {
@@ -51,7 +48,7 @@ class KeyboardAppearanceInfoTests: XCTestCase {
5148
@available(iOS 9.0, *)
5249
func testBelongsToCurrentApp() {
5350
XCTAssertEqual(apperanceInfo.belongsToCurrentApp, false,
54-
"Parsing endFrame from keyboard appearance info failed.")
51+
"Parsing belongsToCurrentApp from keyboard appearance info failed.")
5552
}
5653

5754
func testAnimationDuration() {
@@ -60,12 +57,22 @@ class KeyboardAppearanceInfoTests: XCTestCase {
6057
}
6158

6259
func testAnimationCurve() {
63-
XCTAssertEqual(apperanceInfo.animationCurve, UIViewAnimationCurve(rawValue: 7),
60+
XCTAssertEqual(apperanceInfo.animationCurve, UIViewAnimationCurve(rawValue: 2),
6461
"Parsing animationCurve from keyboard appearance info failed.")
6562
}
6663

67-
// func testAnimateAlong() {
68-
// XCTAssertEqual(apperanceInfo., <#T##expression2: T?##T?#>, <#T##message: String##String#>)
69-
// }
64+
func testAnimateAlong() {
65+
let expectation = expectationWithDescription("Animate along should take 3 seconds")
66+
67+
apperanceInfo.animateAlong({ () -> Void in
68+
// Do animations
69+
}) { (finished) -> Void in
70+
if finished {
71+
expectation.fulfill()
72+
}
73+
}
74+
75+
waitForExpectationsWithTimeout(3.005, handler: nil)
76+
}
7077

7178
}

0 commit comments

Comments
 (0)