Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit fcba684

Browse files
committed
add Example project
1 parent e60ea7d commit fcba684

2 files changed

Lines changed: 85 additions & 12 deletions

File tree

Example/SafeAreaInputAccessoryViewWrapperView/Base.lproj/Main.storyboard

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina5_9" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
9+
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
511
</dependencies>
612
<scenes>
713
<!--View Controller-->
814
<scene sceneID="ufC-wZ-h7g">
915
<objects>
10-
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
16+
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="SafeAreaInputAccessoryView_Example" customModuleProvider="target" sceneMemberID="viewController">
1117
<layoutGuides>
1218
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
1319
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
1420
</layoutGuides>
1521
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
16-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
22+
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
1723
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
18-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
24+
<subviews>
25+
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Tap to enter amount" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="5jk-cJ-uuk">
26+
<rect key="frame" x="40" y="226.66666666666669" width="295" height="44.000000000000057"/>
27+
<constraints>
28+
<constraint firstAttribute="height" constant="44" id="764-AN-8u2"/>
29+
</constraints>
30+
<nil key="textColor"/>
31+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
32+
<textInputTraits key="textInputTraits" returnKeyType="done"/>
33+
<connections>
34+
<outlet property="delegate" destination="vXZ-lx-hvc" id="cXy-o5-vF5"/>
35+
</connections>
36+
</textField>
37+
</subviews>
38+
<color key="backgroundColor" red="0.99519230769230771" green="0.99038461538461542" blue="1" alpha="0.97557255993150682" colorSpace="custom" customColorSpace="displayP3"/>
39+
<constraints>
40+
<constraint firstAttribute="trailing" secondItem="5jk-cJ-uuk" secondAttribute="trailing" constant="40" id="7fH-h3-vhI"/>
41+
<constraint firstItem="5jk-cJ-uuk" firstAttribute="bottom" secondItem="kh9-bI-dsS" secondAttribute="centerY" multiplier="2:3" id="Bff-64-vvZ"/>
42+
<constraint firstItem="5jk-cJ-uuk" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="40" id="bdf-qY-JRt"/>
43+
</constraints>
1944
</view>
45+
<connections>
46+
<outlet property="continueButton" destination="TIE-dD-rQj" id="wnT-Sa-9F1"/>
47+
<outlet property="textField" destination="5jk-cJ-uuk" id="2jJ-c8-Qhr"/>
48+
</connections>
2049
</viewController>
2150
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
51+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="TIE-dD-rQj">
52+
<rect key="frame" x="0.0" y="0.0" width="250" height="53"/>
53+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
54+
<color key="backgroundColor" red="0.37647058820000001" green="0.6705882353" blue="0.27450980390000002" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
55+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
56+
<state key="normal" title="CONTINUE">
57+
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
58+
</state>
59+
<connections>
60+
<action selector="didTapContinueButton:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Aqx-DI-T9y"/>
61+
</connections>
62+
</button>
2263
</objects>
2364
</scene>
2465
</scenes>

Example/SafeAreaInputAccessoryViewWrapperView/ViewController.swift

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,50 @@
77
//
88

99
import UIKit
10+
import SafeAreaInputAccessoryViewWrapperView
1011

1112
class ViewController: UIViewController {
12-
13+
@IBOutlet weak var textField: UITextField!
14+
@IBOutlet private var continueButton: UIButton!
15+
16+
private lazy var wrappedContinueButton: SafeAreaInputAccessoryViewWrapperView = {
17+
return SafeAreaInputAccessoryViewWrapperView(for: continueButton)
18+
}()
19+
20+
// MARK: Input Accessory View
21+
22+
override var canBecomeFirstResponder: Bool {
23+
return true
24+
}
25+
26+
override var inputAccessoryView: UIView? {
27+
return wrappedContinueButton
28+
}
29+
30+
// MARK: View Lifecycle
31+
1332
override func viewDidLoad() {
1433
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
34+
35+
// SafeAreaInputAccessoryViewWrapperView also allows us to dynamically
36+
// size the inputAccessoryView using autolayout, removing the need
37+
// for us to set the frame manually here.
38+
continueButton.heightAnchor.constraint(equalToConstant: 60).isActive = true
39+
40+
// Always show the continue button, even when the keyboard is closed
41+
becomeFirstResponder()
1642
}
43+
}
1744

18-
override func didReceiveMemoryWarning() {
19-
super.didReceiveMemoryWarning()
20-
// Dispose of any resources that can be recreated.
45+
private extension ViewController {
46+
@IBAction func didTapContinueButton(_ sender: Any) {
47+
textField.resignFirstResponder()
2148
}
22-
2349
}
2450

51+
extension ViewController: UITextFieldDelegate {
52+
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
53+
textField.resignFirstResponder()
54+
return true
55+
}
56+
}

0 commit comments

Comments
 (0)