Commit f5487b02 by Olzhas Aldabergenov

chat keyboard and scrolling fixed

parent bf925785
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "65" startingLineNumber = "65"
endingLineNumber = "65" endingLineNumber = "65"
landmarkName = "bind(nodes:)" landmarkName = "bind(_:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies> <dependencies>
<deployment identifier="iOS"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<customFonts key="customFonts"> <customFonts key="customFonts">
<mutableArray key="PT_Sans-Web-Bold.ttf"> <array key="PT_Sans-Web-Bold.ttf">
<string>PTSans-Bold</string> <string>PTSans-Bold</string>
<string>PTSans-Bold</string> </array>
</mutableArray>
</customFonts> </customFonts>
<objects> <objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
...@@ -18,19 +17,16 @@ ...@@ -18,19 +17,16 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5es-8G-PFJ" userLabel="step"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5es-8G-PFJ" userLabel="step">
<rect key="frame" x="20" y="20" width="560" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/> <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ylo-Eb-ARy" userLabel="tipLabel"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ylo-Eb-ARy" userLabel="tipLabel">
<rect key="frame" x="20" y="61" width="560" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/> <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Kwb-av-9cJ" userLabel="GUID"> <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Kwb-av-9cJ" userLabel="GUID">
<rect key="frame" x="15" y="102" width="570" height="44"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="44" id="4oD-g8-RYu"/> <constraint firstAttribute="height" constant="44" id="4oD-g8-RYu"/>
</constraints> </constraints>
...@@ -38,34 +34,31 @@ ...@@ -38,34 +34,31 @@
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
</textField> </textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="zpI-tj-1Ya" userLabel="RegsitrationCode"> <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="zpI-tj-1Ya" userLabel="RegsitrationCode">
<rect key="frame" x="15" y="154" width="570" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits"/> <textInputTraits key="textInputTraits"/>
</textField> </textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gf3-an-afz"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Gf3-an-afz">
<rect key="frame" x="15" y="218" width="570" height="51"/> <color key="backgroundColor" red="0.095081739127635956" green="0.37402468919754028" blue="0.67706954479217529" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.1058823529" green="0.45882352939999999" blue="0.73333333329999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="51" id="v7D-C0-vSa"/> <constraint firstAttribute="height" constant="51" id="v7D-C0-vSa"/>
</constraints> </constraints>
<fontDescription key="fontDescription" name="PTSans-Bold" family="PT Sans" pointSize="17"/> <fontDescription key="fontDescription" name="PTSans-Bold" family="PT Sans" pointSize="17"/>
<state key="normal" title="Далее"> <state key="normal" title="Далее">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state> </state>
</button> </button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zMr-Jb-Ez2"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zMr-Jb-Ez2">
<rect key="frame" x="15" y="284" width="570" height="51"/> <color key="backgroundColor" red="0.26219156384468079" green="0.33811080455780029" blue="0.45045208930969238" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.3294117647" green="0.41568627450000001" blue="0.52549019610000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="51" id="bhd-Hz-5nT"/> <constraint firstAttribute="height" constant="51" id="bhd-Hz-5nT"/>
</constraints> </constraints>
<fontDescription key="fontDescription" name="PTSans-Bold" family="PT Sans" pointSize="17"/> <fontDescription key="fontDescription" name="PTSans-Bold" family="PT Sans" pointSize="17"/>
<state key="normal" title="Отмена"> <state key="normal" title="Отмена">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state> </state>
</button> </button>
</subviews> </subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints> <constraints>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="zMr-Jb-Ez2" secondAttribute="bottom" constant="5" id="1Mq-VX-Mxs"/> <constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="zMr-Jb-Ez2" secondAttribute="bottom" constant="5" id="1Mq-VX-Mxs"/>
<constraint firstItem="Kwb-av-9cJ" firstAttribute="top" secondItem="Ylo-Eb-ARy" secondAttribute="bottom" constant="20" id="2Yu-B8-ktj"/> <constraint firstItem="Kwb-av-9cJ" firstAttribute="top" secondItem="Ylo-Eb-ARy" secondAttribute="bottom" constant="20" id="2Yu-B8-ktj"/>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import UIKit import UIKit
class BotViewController: UIViewController { class BotViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var messageField: UITextField! @IBOutlet weak var messageField: UITextField!
@IBOutlet weak var tableView: UITableView! @IBOutlet weak var tableView: UITableView!
...@@ -19,6 +19,7 @@ class BotViewController: UIViewController { ...@@ -19,6 +19,7 @@ class BotViewController: UIViewController {
weak var activeField: UITextField? weak var activeField: UITextField?
var messagesList : [BotResult] = [] var messagesList : [BotResult] = []
var heightAtIndexPath = NSMutableDictionary()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -31,14 +32,15 @@ class BotViewController: UIViewController { ...@@ -31,14 +32,15 @@ class BotViewController: UIViewController {
self.circleButton.userInteractionEnabled = true self.circleButton.userInteractionEnabled = true
self.circleButton.addGestureRecognizer(tap) self.circleButton.addGestureRecognizer(tap)
addMessage("Здравствуйте! Я Ваш помощник на сайте Казахтелеком. Постараюсь ответить на большинство Ваших вопросов.", type: 0)
NSNotificationCenter.defaultCenter().addObserver(self, NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.keyboardNotification(_:)), selector: #selector(self.keyboardNotification(_:)),
name: UIKeyboardWillChangeFrameNotification, name: UIKeyboardWillChangeFrameNotification,
object: nil) object: nil)
initializeTap() initializeTap()
addMessage("Здравствуйте! Я Ваш помощник на сайте Казахтелеком. Постараюсь ответить на большинство Ваших вопросов.", type: 0)
} }
func initializeTap() { func initializeTap() {
...@@ -99,7 +101,6 @@ class BotViewController: UIViewController { ...@@ -99,7 +101,6 @@ class BotViewController: UIViewController {
func textFieldShouldReturn(textField: UITextField) -> Bool { func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder() textField.resignFirstResponder()
self.tableView.scrollToBottom(true)
return true return true
} }
...@@ -114,8 +115,23 @@ class BotViewController: UIViewController { ...@@ -114,8 +115,23 @@ class BotViewController: UIViewController {
var botNodes : [BotNode] = [] var botNodes : [BotNode] = []
botNodes.append(botNode) botNodes.append(botNode)
botResult.nodes = botNodes botResult.nodes = botNodes
self.addMessage(botResult)
}
func addMessage(botResult: BotResult) {
self.tableView.beginUpdates()
self.messagesList.append(botResult) self.messagesList.append(botResult)
self.tableView.reloadData()
let indexPath = NSIndexPath(forRow: (self.messagesList.count - 1), inSection: 0)
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
self.tableView.endUpdates()
self.tableView.scrollToBottom(true)
}
func reloadTable() {
} }
func numberOfSectionsInTableView(tableView: UITableView) -> Int { func numberOfSectionsInTableView(tableView: UITableView) -> Int {
...@@ -138,19 +154,13 @@ class BotViewController: UIViewController { ...@@ -138,19 +154,13 @@ class BotViewController: UIViewController {
} }
} }
func reloadTable() {
self.tableView.reloadData()
}
func getChildNodes(id: Int) { func getChildNodes(id: Int) {
Facade.sharedInstance().childBot(String(id), onSuccess: { (botResult) in Facade.sharedInstance().childBot(String(id), onSuccess: { (botResult) in
if botResult.count != 0 { if botResult.count != 0 {
self.messagesList.append(botResult) self.addMessage(botResult)
self.tableView.reloadData()
} else { } else {
self.addMessage("Извините, по вашему запросу ничего не нашлось", type: 0) self.addMessage("Извините, по вашему запросу ничего не нашлось", type: 0)
} }
self.tableView.scrollToBottom(true)
}) { (error) in }) { (error) in
AlertViewUtil.showErrorAlert(error, vc: self) AlertViewUtil.showErrorAlert(error, vc: self)
} }
...@@ -165,22 +175,32 @@ class BotViewController: UIViewController { ...@@ -165,22 +175,32 @@ class BotViewController: UIViewController {
self.messageField.text = "" self.messageField.text = ""
addMessage(messageStr, type: 1) addMessage(messageStr, type: 1)
self.tableView.scrollToBottom(true)
Facade.sharedInstance().askBot(messageStr, onSuccess: { (botResult) in Facade.sharedInstance().askBot(messageStr, onSuccess: { (botResult) in
if botResult.count != 0 { if botResult.count != 0 {
self.messagesList.append(botResult) self.addMessage(botResult)
self.tableView.reloadData()
} else { } else {
self.addMessage("Извините, по вашему запросу ничего не нашлось", type: 0) self.addMessage("Извините, по вашему запросу ничего не нашлось", type: 0)
} }
self.tableView.scrollToBottom(true)
}) { (error) in }) { (error) in
AlertViewUtil.showErrorAlert(error, vc: self) AlertViewUtil.showErrorAlert(error, vc: self)
} }
}
//dismissKeyboard() func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let height = self.heightAtIndexPath.objectForKey(indexPath)
if ((height) != nil) {
return CGFloat(height!.floatValue)
} else {
return UITableViewAutomaticDimension
}
} }
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let height = cell.frame.size.height
self.heightAtIndexPath.setObject(height, forKey: indexPath)
}
} }
extension UITableView { extension UITableView {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment