Skip to content

Commit

Permalink
hiding keyboard when tapped collectionView area
Browse files Browse the repository at this point in the history
  • Loading branch information
pgs-dkanak committed May 26, 2017
1 parent a132694 commit bce5527
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions MessagesView/MessagesInputToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class MessagesInputToolbar: UIToolbar {
toolbarContentView.frame = self.bounds
}

override func resignFirstResponder() -> Bool {
return toolbarContentView.resignFirstResponder()
}

func rightButton(show: Bool, animated: Bool) {
toolbarContentView.righButton(show: show, animated: animated)
}
Expand Down
8 changes: 6 additions & 2 deletions MessagesView/MessagesToolbarContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MessagesToolbarContentView: UIView {
}

if settings.leftButtonHidesKeyboard {
messageEditorTextView.resignFirstResponder()
_ = resignFirstResponder()
}
}

Expand All @@ -72,10 +72,14 @@ class MessagesToolbarContentView: UIView {
}

if settings.rightButtonHidesKeyboard {
messageEditorTextView.resignFirstResponder()
_ = resignFirstResponder()
}
}

override func resignFirstResponder() -> Bool {
return messageEditorTextView.resignFirstResponder()
}

class func fromNib() -> MessagesToolbarContentView {
let bundle = Bundle(for: MessagesToolbarContentView.classForCoder())
let nibViews = bundle.loadNibNamed(String(describing: MessagesToolbarContentView.self), owner: nil, options: nil)
Expand Down
3 changes: 3 additions & 0 deletions MessagesView/MessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ public class MessagesView: UIView {
messagesCollectionView.register(UICollectionReusableView.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: Key.messagesCollectionViewFooter)
}

@IBAction func didTapCollectionViewArea(_ sender: Any) {
_ = messagesInputToolbar.resignFirstResponder()
}

public func refresh() {
DispatchQueue.main.async {
Expand Down
14 changes: 11 additions & 3 deletions MessagesView/MessagesView.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1217" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -23,6 +23,7 @@
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="3Nf-do-eXM" customClass="MessagesCollectionView" customModule="MessagesView" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="617"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="0.0" minimumInteritemSpacing="10" id="L0d-27-qxR">
<size key="itemSize" width="301" height="60"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
Expand All @@ -33,6 +34,7 @@
<connections>
<outlet property="dataSource" destination="-1" id="fQj-re-a1Y"/>
<outlet property="delegate" destination="-1" id="sFQ-em-SnE"/>
<outletCollection property="gestureRecognizers" destination="a0M-QB-WkO" appends="YES" id="3xr-KD-IIO"/>
</connections>
</collectionView>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dHh-JD-Gtu" customClass="MessagesInputToolbar" customModule="MessagesView" customModuleProvider="target">
Expand All @@ -46,6 +48,7 @@
</toolbar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="3Nf-do-eXM" firstAttribute="leading" secondItem="xMm-vM-6w5" secondAttribute="leading" id="2JO-E5-trk"/>
<constraint firstAttribute="bottom" secondItem="dHh-JD-Gtu" secondAttribute="bottom" id="CvQ-ma-VhN"/>
Expand All @@ -56,5 +59,10 @@
<constraint firstItem="dHh-JD-Gtu" firstAttribute="top" secondItem="3Nf-do-eXM" secondAttribute="bottom" id="y2z-Ik-10e"/>
</constraints>
</view>
<tapGestureRecognizer id="a0M-QB-WkO">
<connections>
<action selector="didTapCollectionViewArea:" destination="-1" id="X6m-rn-BDG"/>
</connections>
</tapGestureRecognizer>
</objects>
</document>

0 comments on commit bce5527

Please sign in to comment.