Skip to content

Commit

Permalink
Merge pull request #247 from Alexookah/master
Browse files Browse the repository at this point in the history
HUD moves to accomodate keyboard #2
  • Loading branch information
PGLongo authored Apr 10, 2019
2 parents ec32e5b + 72b2d63 commit 6eb488e
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 35 deletions.
18 changes: 18 additions & 0 deletions Demo/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ import UIKit
import PKHUD

class DemoViewController: UIViewController {

let hiddenTextField = UITextField(frame: CGRect.zero)


override func viewDidLoad() {
super.viewDidLoad()

view.addSubview(hiddenTextField)
HUD.registerForKeyboardNotifications()

HUD.dimsBackground = false
HUD.allowsInteraction = false
}

@IBAction func showHideKeyboard(_ sender: Any) {
if hiddenTextField.isEditing {
view.endEditing(true)
} else {
hiddenTextField.becomeFirstResponder()
}
}

@IBAction func showAnimatedSuccessHUD(_ sender: AnyObject) {
HUD.flash(.success, delay: 2.0)
Expand Down Expand Up @@ -50,6 +64,10 @@ class DemoViewController: UIViewController {
print("License Obtained.")
}
}

deinit {
HUD.deregisterFromKeyboardNotifications()
}

/*

Expand Down
85 changes: 52 additions & 33 deletions Demo/Storyboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="D2U-NN-2aL">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="D2U-NN-2aL">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Demo View Controller-->
Expand All @@ -14,100 +18,115 @@
<viewControllerLayoutGuide type="bottom" id="sKS-gL-TO9"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="w4E-8X-Jzi">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="background" translatesAutoresizingMaskIntoConstraints="NO" id="ZJp-P0-C2o" userLabel="Background">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="-4" y="0.0" width="383" height="667"/>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" misplaced="YES" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="rqP-5y-Qfl">
<rect key="frame" x="40" y="328" width="520" height="304"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="rqP-5y-Qfl">
<rect key="frame" x="36" y="291" width="303" height="356"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hDX-YT-2be">
<rect key="frame" x="0.0" y="0.0" width="303" height="44"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.66000000000000003" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="e4i-A7-lgx"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Show/Hide Keyboard">
<color key="titleColor" red="0.25" green="0.25" blue="0.25" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showHideKeyboard:" destination="D2U-NN-2aL" eventType="touchUpInside" id="dkr-Ml-4IT"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nZ4-Lx-cqz">
<rect key="frame" x="0.0" y="0.0" width="520" height="44"/>
<color key="backgroundColor" white="1" alpha="0.66000000000000003" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="52" width="303" height="44"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.66000000000000003" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="yyh-ba-2Q5"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Animated Success HUD">
<color key="titleColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="0.25" green="0.25" blue="0.25" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showAnimatedSuccessHUD:" destination="D2U-NN-2aL" eventType="touchUpInside" id="k9E-hd-08Z"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="x5z-e1-I63">
<rect key="frame" x="0.0" y="52" width="520" height="44"/>
<color key="backgroundColor" white="1" alpha="0.66000000000000003" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="104" width="303" height="44"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.66000000000000003" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="O2F-o7-Xsw"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Animated Error HUD">
<color key="titleColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="0.25" green="0.25" blue="0.25" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showAnimatedErrorHUD:" destination="D2U-NN-2aL" eventType="touchUpInside" id="Cyd-W9-1e2"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rmq-Eh-KX3">
<rect key="frame" x="0.0" y="104" width="520" height="44"/>
<color key="backgroundColor" white="1" alpha="0.66000000000000003" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="156" width="303" height="44"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.66000000000000003" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="RY7-k4-4pQ"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Animated Progress HUD">
<color key="titleColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="0.25" green="0.25" blue="0.25" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showAnimatedProgressHUD:" destination="D2U-NN-2aL" eventType="touchUpInside" id="Vu1-gd-bzp"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="X4n-2l-pZk">
<rect key="frame" x="0.0" y="156" width="520" height="44"/>
<color key="backgroundColor" white="1" alpha="0.66000000000000003" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="208" width="303" height="44"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.66000000000000003" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="kcT-Ut-AmL"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Animated Status Progress HUD">
<color key="titleColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="0.25" green="0.25" blue="0.25" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showAnimatedStatusProgressHUD:" destination="D2U-NN-2aL" eventType="touchUpInside" id="R2f-zr-F2H"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NfX-TV-8Iq">
<rect key="frame" x="0.0" y="208" width="520" height="44"/>
<color key="backgroundColor" white="1" alpha="0.66000000000000003" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="260" width="303" height="44"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.66000000000000003" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="hbA-LY-ItN"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Custom Animated Progress HUD">
<color key="titleColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="0.25" green="0.25" blue="0.25" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showCustomProgressHUD:" destination="D2U-NN-2aL" eventType="touchUpInside" id="g9n-80-Y6g"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1XL-mO-npD">
<rect key="frame" x="0.0" y="260" width="520" height="44"/>
<color key="backgroundColor" white="1" alpha="0.66000000000000003" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="312" width="303" height="44"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.66000000000000003" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="uLS-Fh-Fh5"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" title="Text HUD">
<color key="titleColor" white="0.25" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleColor" red="0.25" green="0.25" blue="0.25" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showTextHUD:" destination="D2U-NN-2aL" eventType="touchUpInside" id="eJg-na-gUk"/>
Expand All @@ -116,7 +135,7 @@
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="sKS-gL-TO9" firstAttribute="top" secondItem="rqP-5y-Qfl" secondAttribute="bottom" constant="20" id="0Xk-Fo-1a2"/>
<constraint firstItem="rqP-5y-Qfl" firstAttribute="leading" secondItem="w4E-8X-Jzi" secondAttribute="leadingMargin" constant="20" id="6dE-Gf-0ue"/>
Expand Down
9 changes: 9 additions & 0 deletions PKHUD/HUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public final class HUD {
HUD.show(content, onView: view)
HUD.hide(afterDelay: delay, completion: completion)
}

// MARK: Keyboard Methods
public static func registerForKeyboardNotifications() {
PKHUD.sharedHUD.registerForKeyboardNotifications()
}

public static func deregisterFromKeyboardNotifications() {
PKHUD.sharedHUD.deregisterFromKeyboardNotifications()
}

// MARK: Private methods
fileprivate static func contentView(_ content: HUDContentType) -> UIView {
Expand Down
8 changes: 8 additions & 0 deletions PKHUD/PKHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ open class PKHUD: NSObject {
animatingContentView.stopAnimation?()
}
}

internal func registerForKeyboardNotifications() {
container.registerForKeyboardNotifications()
}

internal func deregisterFromKeyboardNotifications() {
container.deregisterFromKeyboardNotifications()
}

// MARK: Timer callbacks

Expand Down
Loading

0 comments on commit 6eb488e

Please sign in to comment.