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

Commit

Permalink
Merge pull request #16 from nodes-ios/swift-3.0
Browse files Browse the repository at this point in the history
Swift 3.0 version
  • Loading branch information
NickSkull committed Dec 14, 2016
2 parents a3a16a5 + 29108a0 commit d6a6fb6
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 123 deletions.
2 changes: 1 addition & 1 deletion Example/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "nodes-ios/KeyboardHelper" "master"
github "nodes-ios/KeyboardHelper" "swift-3.0"
2 changes: 1 addition & 1 deletion Example/Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "nodes-ios/KeyboardHelper" "30ed3728bf10b7d2a606d1e23bb23c12eea02222"
github "nodes-ios/KeyboardHelper" "58d7c2bf19f7bc93d733290f06ae0eedf03f18a5"
3 changes: 3 additions & 0 deletions Example/KeyboardHelperDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
TargetAttributes = {
29F30E661C807E2A00C77AF4 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0810;
};
};
};
Expand Down Expand Up @@ -289,6 +290,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = dk.nodes.KeyboardHelperDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -305,6 +307,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = dk.nodes.KeyboardHelperDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
12 changes: 6 additions & 6 deletions Example/KeyboardHelperDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
14 changes: 7 additions & 7 deletions Example/KeyboardHelperDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import KeyboardHelper

class ViewController: UIViewController, KeyboardNotificationDelegate {

private var tapGesture: UITapGestureRecognizer!
private var keyboardHelper : KeyboardHelper?
fileprivate var tapGesture: UITapGestureRecognizer!
fileprivate var keyboardHelper : KeyboardHelper?
@IBOutlet weak var scrollView: UIScrollView!

override func viewDidLoad() {
Expand All @@ -21,7 +21,7 @@ class ViewController: UIViewController, KeyboardNotificationDelegate {

self.tapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.dismissKeyboard))
self.view.addGestureRecognizer(tapGesture)
self.tapGesture.enabled = true
self.tapGesture.isEnabled = true

self.keyboardHelper = KeyboardHelper(delegate: self)
}
Expand All @@ -30,20 +30,20 @@ class ViewController: UIViewController, KeyboardNotificationDelegate {
self.view.endEditing(true)
}

func keyboardWillAppear(info: KeyboardAppearanceInfo) {
func keyboardWillAppear(_ info: KeyboardAppearanceInfo) {
info.animateAlong({ () -> Void in
let insets = UIEdgeInsetsMake(0, 0, info.endFrame.size.height, 0)
self.scrollView.contentInset = insets
self.scrollView.scrollIndicatorInsets = insets
}) { finished in }
}

func keyboardWillDisappear(info: KeyboardAppearanceInfo) {
UIView.animateWithDuration(NSTimeInterval(info.animationDuration),
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo) {
UIView.animate(withDuration: TimeInterval(info.animationDuration),
delay: 0,
options: info.animationOptions,
animations: {
let insets = UIEdgeInsetsZero
let insets = UIEdgeInsets.zero
self.scrollView.contentInset = insets
self.scrollView.scrollIndicatorInsets = insets
},
Expand Down
7 changes: 3 additions & 4 deletions KeyboardHelper.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "KeyboardHelper"
s.version = "0.9.2"
s.version = "1.0.0"
s.summary = "Handle UIKeyboard with ease, delegation and strongly typed user info included!"

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -66,7 +66,7 @@ Pod::Spec.new do |s|
# s.platform = :ios, "5.0"

# When using multiple platforms
s.ios.deployment_target = "8.1"
s.ios.deployment_target = "8.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"
Expand All @@ -78,7 +78,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/nodes-ios/KeyboardHelper.git", :tag => "0.9.2" }
s.source = { :git => "https://github.com/nodes-ios/KeyboardHelper.git", :tag => s.version }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down Expand Up @@ -134,4 +134,3 @@ Pod::Spec.new do |s|
# s.dependency "JSONKit", "~> 1.4"

end

16 changes: 11 additions & 5 deletions KeyboardHelper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = Nodes;
TargetAttributes = {
275BCA761C57C9F800FF3647 = {
Expand Down Expand Up @@ -275,8 +275,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -322,8 +324,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -364,7 +368,7 @@
SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -382,7 +386,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME)-Swift.h";
SWIFT_VERSION = 2.3;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -393,7 +398,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -404,7 +409,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.KeyboardHelperTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
28 changes: 14 additions & 14 deletions KeyboardHelper/Classes/KeyboardAppearanceInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// KeyboardAppearanceInfo.swift
// KeyboardHelper
//
// Created by Timmi Trinks on 04/02/16.
// Created by Kasper Welner on 04/02/16.
// Copyright © 2016 Nodes. All rights reserved.
//

Expand All @@ -14,10 +14,10 @@ import UIKit
*/
public struct KeyboardAppearanceInfo {

public let notification: NSNotification
public let userInfo: [NSObject: AnyObject]
public let notification: Notification
public let userInfo: [AnyHashable: Any]

public init(notification: NSNotification) {
public init(notification: Notification) {
self.notification = notification
self.userInfo = notification.userInfo ?? [:]
}
Expand All @@ -27,15 +27,15 @@ public struct KeyboardAppearanceInfo {
Return a `CGRect` or `CGRectZero`.
*/
public var beginFrame: CGRect {
return userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue ?? CGRectZero
return (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
}

/**
Getter for the UIKeyboard frame end infokey.
Return a `CGRect` or `CGRectZero`.
*/
public var endFrame: CGRect {
return userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue ?? CGRectZero
return (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? .zero
}

/**
Expand All @@ -45,7 +45,7 @@ public struct KeyboardAppearanceInfo {
*/
public var belongsToCurrentApp: Bool {
if #available(iOS 9.0, *) {
return userInfo[UIKeyboardIsLocalUserInfoKey]?.boolValue ?? true
return (userInfo[UIKeyboardIsLocalUserInfoKey] as? Bool) ?? true
} else {
return true
}
Expand All @@ -56,16 +56,16 @@ public struct KeyboardAppearanceInfo {
By default: `0.25`.
*/
public var animationDuration: Double {
return userInfo[UIKeyboardAnimationDurationUserInfoKey]?.doubleValue ?? 0.25
return (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0.25
}

/**
Getter for the animation curve.
By default: `EaseInOut`.
*/
public var animationCurve: UIViewAnimationCurve {
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .EaseInOut }
return UIViewAnimationCurve(rawValue: value) ?? .EaseInOut
guard let value = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? Int else { return .easeInOut }
return UIViewAnimationCurve(rawValue: value) ?? .easeInOut
}

/**
Expand All @@ -84,12 +84,12 @@ public struct KeyboardAppearanceInfo {
- animationBlock: Animation that should happen.
- completion: Function that happens after the animation is finished.
*/
public func animateAlong(animationBlock: () -> Void, completion: (finished: Bool) -> Void) {
UIView.animateWithDuration(
animationDuration,
public func animateAlong(_ animationBlock: @escaping (() -> Void), completion: @escaping ((_ finished: Bool) -> Void) = { _ in }) {
UIView.animate(
withDuration: animationDuration,
delay: 0.0,
options: animationOptions,
animations: animationBlock,
completion: completion
)}
}
}
16 changes: 8 additions & 8 deletions KeyboardHelper/Classes/KeyboardHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// KeyboardHelper.swift
// KeyboardHelper
//
// Created by Timmi Trinks on 27/01/16.
// Created by Kasper Welner on 27/01/16.
// Copyright © 2016 Nodes. All rights reserved.
//

Expand All @@ -19,13 +19,13 @@ public protocol KeyboardNotificationDelegate: class {
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will appaear.
- Parameter info: Struct `KeyboardAppearanceInfo`.
*/
func keyboardWillAppear(info: KeyboardAppearanceInfo)
func keyboardWillAppear(_ info: KeyboardAppearanceInfo)

/**
This function will recongnize a change of `KeyboardAppearanceInfo` and will be fired when the keyboard will disappaear.
- Parameter info: Struct `KeyboardAppearanceInfo`.
*/
func keyboardWillDisappear(info: KeyboardAppearanceInfo)
func keyboardWillDisappear(_ info: KeyboardAppearanceInfo)
}

/**
Expand All @@ -45,25 +45,25 @@ public class KeyboardHelper {
required public init(delegate: KeyboardNotificationDelegate) {
self.delegate = delegate

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: UIKeyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillAppear(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(KeyboardHelper.keyboardWillDisappear(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}

private init() {
delegate = nil
}

dynamic private func keyboardWillAppear(note: NSNotification) {
dynamic private func keyboardWillAppear(_ note: Notification) {
let info = KeyboardAppearanceInfo(notification: note)
self.delegate?.keyboardWillAppear(info)
}

dynamic private func keyboardWillDisappear(note: NSNotification) {
dynamic private func keyboardWillDisappear(_ note: Notification) {
let info = KeyboardAppearanceInfo(notification: note)
self.delegate?.keyboardWillDisappear(info)
}

deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
NotificationCenter.default.removeObserver(self)
}
}
Loading

0 comments on commit d6a6fb6

Please sign in to comment.