Skip to content

Commit 1bba4af

Browse files
committed
Initial commit :)
0 parents  commit 1bba4af

File tree

21 files changed

+1497
-0
lines changed

21 files changed

+1497
-0
lines changed

.bundle/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
BUNDLE_PATH: "vendor/bundle"
3+
BUNDLE_DISABLE_SHARED_GEMS: "true"

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
3+
**/xcuserdata
4+
*.pbxuser
5+
*.mode1v3
6+
7+
Pods/
8+
vendor/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "29x29",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "29x29",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "40x40",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "40x40",
31+
"scale" : "3x"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"size" : "60x60",
36+
"scale" : "2x"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"size" : "60x60",
41+
"scale" : "3x"
42+
}
43+
],
44+
"info" : {
45+
"version" : 1,
46+
"author" : "xcode"
47+
}
48+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
5+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="EHf-IW-A2E">
10+
<objects>
11+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
14+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="53" y="375"/>
25+
</scene>
26+
</scenes>
27+
</document>

Demo/Sources/AppDelegate.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// AppDelegate.swift
3+
// Demo
4+
//
5+
// Created by Suyeol Jeon on 09/10/2016.
6+
// Copyright © 2016 Suyeol Jeon. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
import Then
12+
import UITextView_Placeholder
13+
14+
@UIApplicationMain
15+
final class AppDelegate: UIResponder, UIApplicationDelegate {
16+
17+
var window: UIWindow?
18+
19+
func application(
20+
_ application: UIApplication,
21+
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
22+
) -> Bool {
23+
let window = UIWindow(frame: UIScreen.main.bounds)
24+
window.backgroundColor = .white
25+
window.rootViewController = UINavigationController(rootViewController: ViewController())
26+
window.makeKeyAndVisible()
27+
28+
self.window = window
29+
return true
30+
}
31+
32+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
//
2+
// ViewController.swift
3+
// Demo
4+
//
5+
// Created by Suyeol Jeon on 09/10/2016.
6+
// Copyright © 2016 Suyeol Jeon. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
import RxKeyboard
12+
import RxSwift
13+
14+
class ViewController: UIViewController {
15+
16+
let textView = UITextView().then {
17+
$0.font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
18+
$0.placeholder = "Scroll down to dismiss keyboard."
19+
$0.isEditable = true
20+
$0.alwaysBounceVertical = true
21+
$0.keyboardDismissMode = .interactive
22+
$0.translatesAutoresizingMaskIntoConstraints = false
23+
}
24+
let toolbar = UIToolbar().then {
25+
$0.translatesAutoresizingMaskIntoConstraints = false
26+
}
27+
var toolbarBottomConstraint: NSLayoutConstraint?
28+
let labelItem = UIBarButtonItem(title: nil, style: .plain, target: nil, action: nil).then {
29+
$0.isEnabled = false
30+
}
31+
let doneButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
32+
33+
let disposeBag = DisposeBag()
34+
35+
init() {
36+
super.init(nibName: nil, bundle: nil)
37+
self.title = "RxKeyboard Demo"
38+
39+
self.toolbar.items = [
40+
UIBarButtonItem(image: self.makeUpArrowImage(), style: .plain, target: nil, action: nil)
41+
.then { $0.isEnabled = false },
42+
UIBarButtonItem(image: self.makeDownArrowImage(), style: .plain, target: nil, action: nil)
43+
.then { $0.isEnabled = false },
44+
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
45+
self.labelItem,
46+
UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
47+
self.doneButtonItem,
48+
]
49+
}
50+
51+
required init?(coder aDecoder: NSCoder) {
52+
fatalError("init(coder:) has not been implemented")
53+
}
54+
55+
override func viewDidLoad() {
56+
super.viewDidLoad()
57+
self.textView.becomeFirstResponder()
58+
self.view.addSubview(self.textView)
59+
self.view.addSubview(self.toolbar)
60+
self.setupConstraints()
61+
62+
RxKeyboard.instance.visibleHeight
63+
.drive(onNext: { [weak self] keyboardVisibleHeight in
64+
self?.toolbarBottomConstraint?.constant = -keyboardVisibleHeight
65+
self?.view.setNeedsLayout()
66+
UIView.animate(withDuration: 0) {
67+
self?.view.layoutIfNeeded()
68+
}
69+
})
70+
.addDisposableTo(self.disposeBag)
71+
72+
RxKeyboard.instance.visibleHeight
73+
.drive(onNext: { [weak self] in
74+
self?.labelItem.title = "height: \($0)"
75+
})
76+
.addDisposableTo(self.disposeBag)
77+
78+
self.doneButtonItem.rx.tap
79+
.subscribe(onNext: { [weak self] in
80+
self?.textView.resignFirstResponder()
81+
})
82+
.addDisposableTo(self.disposeBag)
83+
}
84+
85+
86+
// MARK: Auto Layout
87+
88+
private func setupConstraints() {
89+
// text view
90+
NSLayoutConstraint.activate([
91+
NSLayoutConstraint(
92+
item: self.textView,
93+
attribute: .width,
94+
relatedBy: .equal,
95+
toItem: self.view,
96+
attribute: .width,
97+
multiplier: 1,
98+
constant: 0
99+
),
100+
NSLayoutConstraint(
101+
item: self.textView,
102+
attribute: .height,
103+
relatedBy: .equal,
104+
toItem: self.view,
105+
attribute: .height,
106+
multiplier: 1,
107+
constant: 0
108+
),
109+
])
110+
111+
// toolbar
112+
self.toolbarBottomConstraint = NSLayoutConstraint(
113+
item: self.toolbar,
114+
attribute: .bottom,
115+
relatedBy: .equal,
116+
toItem: self.view,
117+
attribute: .bottom,
118+
multiplier: 1,
119+
constant: 0
120+
)
121+
guard let toolbarBottomConstraint = self.toolbarBottomConstraint else { return }
122+
NSLayoutConstraint.activate([
123+
NSLayoutConstraint(
124+
item: self.toolbar,
125+
attribute: .width,
126+
relatedBy: .equal,
127+
toItem: self.view,
128+
attribute: .width,
129+
multiplier: 1,
130+
constant: 0
131+
),
132+
NSLayoutConstraint(
133+
item: self.toolbar,
134+
attribute: .height,
135+
relatedBy: .equal,
136+
toItem: nil,
137+
attribute: .notAnAttribute,
138+
multiplier: 1,
139+
constant: 44
140+
),
141+
toolbarBottomConstraint,
142+
])
143+
}
144+
145+
146+
// MARK: Image Factory
147+
148+
private func makeUpArrowImage() -> UIImage? {
149+
let size = CGSize(width: 21, height: 12)
150+
let lineWidth: CGFloat = 1.5
151+
UIGraphicsBeginImageContextWithOptions(size, false, 0)
152+
153+
guard let context = UIGraphicsGetCurrentContext() else { return nil }
154+
context.move(to: CGPoint(x: lineWidth / 2, y: size.height - lineWidth / 2))
155+
context.addLine(to: CGPoint(x: size.width / 2, y: lineWidth / 2))
156+
context.addLine(to: CGPoint(x: size.width - lineWidth / 2, y: size.height - lineWidth / 2))
157+
context.setLineWidth(lineWidth)
158+
159+
UIColor.black.setStroke()
160+
context.strokePath()
161+
162+
let image = UIGraphicsGetImageFromCurrentImageContext()
163+
UIGraphicsEndImageContext()
164+
return image
165+
}
166+
167+
private func makeDownArrowImage() -> UIImage? {
168+
let size = CGSize(width: 21, height: 12)
169+
let lineWidth: CGFloat = 1.5
170+
UIGraphicsBeginImageContextWithOptions(size, false, 0)
171+
172+
guard let context = UIGraphicsGetCurrentContext() else { return nil }
173+
context.move(to: CGPoint(x: lineWidth / 2, y: lineWidth / 2))
174+
context.addLine(to: CGPoint(x: size.width / 2, y: size.height - lineWidth / 2))
175+
context.addLine(to: CGPoint(x: size.width - lineWidth / 2, y: lineWidth / 2))
176+
context.setLineWidth(lineWidth)
177+
178+
UIColor.black.setStroke()
179+
context.strokePath()
180+
181+
let image = UIGraphicsGetImageFromCurrentImageContext()
182+
UIGraphicsEndImageContext()
183+
return image
184+
}
185+
186+
}

Demo/Supporting Files/Info.plist

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
<key>LSRequiresIPhoneOS</key>
22+
<true/>
23+
<key>UILaunchStoryboardName</key>
24+
<string>LaunchScreen</string>
25+
<key>UIRequiredDeviceCapabilities</key>
26+
<array>
27+
<string>armv7</string>
28+
</array>
29+
<key>UISupportedInterfaceOrientations</key>
30+
<array>
31+
<string>UIInterfaceOrientationPortrait</string>
32+
<string>UIInterfaceOrientationLandscapeLeft</string>
33+
<string>UIInterfaceOrientationLandscapeRight</string>
34+
</array>
35+
</dict>
36+
</plist>

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
ruby '~> 2.3'
3+
4+
gem 'cocoapods', '~> 1.0'

0 commit comments

Comments
 (0)