From 973117d2550b664794c327798997aee7013d97cd Mon Sep 17 00:00:00 2001 From: Ernesto Rivera Date: Mon, 22 Oct 2018 16:24:35 -0400 Subject: [PATCH 1/3] Add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bce6af --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +xcuserdata From 84b816835f1334ae955c6f4e37450939cf21cc0f Mon Sep 17 00:00:00 2001 From: Ernesto Rivera Date: Mon, 22 Oct 2018 16:25:28 -0400 Subject: [PATCH 2/3] Better way to initialize tableView and shadowView --- SearchTextField/Classes/SearchTextField.swift | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/SearchTextField/Classes/SearchTextField.swift b/SearchTextField/Classes/SearchTextField.swift index 2f6ac23..4270f2b 100755 --- a/SearchTextField/Classes/SearchTextField.swift +++ b/SearchTextField/Classes/SearchTextField.swift @@ -205,28 +205,30 @@ open class SearchTextField: UITextField { // Create the filter table and shadow view fileprivate func buildSearchTableView() { - if let tableView = tableView, let shadowView = shadowView { - tableView.layer.masksToBounds = true - tableView.layer.borderWidth = theme.borderWidth > 0 ? theme.borderWidth : 0.5 - tableView.dataSource = self - tableView.delegate = self - tableView.separatorInset = UIEdgeInsets.zero - tableView.tableHeaderView = resultsListHeader - if forceRightToLeft { - tableView.semanticContentAttribute = .forceRightToLeft - } - - shadowView.backgroundColor = UIColor.lightText - shadowView.layer.shadowColor = UIColor.black.cgColor - shadowView.layer.shadowOffset = CGSize.zero - shadowView.layer.shadowOpacity = 1 - - self.window?.addSubview(tableView) - } else { - tableView = UITableView(frame: CGRect.zero) - shadowView = UIView(frame: CGRect.zero) + guard let tableView = tableView, let shadowView = shadowView else { + self.tableView = UITableView(frame: CGRect.zero) + self.shadowView = UIView(frame: CGRect.zero) + buildSearchTableView() + return + } + + tableView.layer.masksToBounds = true + tableView.layer.borderWidth = theme.borderWidth > 0 ? theme.borderWidth : 0.5 + tableView.dataSource = self + tableView.delegate = self + tableView.separatorInset = UIEdgeInsets.zero + tableView.tableHeaderView = resultsListHeader + if forceRightToLeft { + tableView.semanticContentAttribute = .forceRightToLeft } + shadowView.backgroundColor = UIColor.lightText + shadowView.layer.shadowColor = UIColor.black.cgColor + shadowView.layer.shadowOffset = CGSize.zero + shadowView.layer.shadowOpacity = 1 + + self.window?.addSubview(tableView) + redrawSearchTableView() } From c33eca9bebfc96451c79d195173f4aab6d127f2d Mon Sep 17 00:00:00 2001 From: Ernesto Rivera Date: Mon, 22 Oct 2018 16:25:57 -0400 Subject: [PATCH 3/3] Prevent animating table view from (0, 0) origin --- SearchTextField/Classes/SearchTextField.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/SearchTextField/Classes/SearchTextField.swift b/SearchTextField/Classes/SearchTextField.swift index 4270f2b..65bcaa4 100755 --- a/SearchTextField/Classes/SearchTextField.swift +++ b/SearchTextField/Classes/SearchTextField.swift @@ -301,6 +301,7 @@ open class SearchTextField: UITextField { tableViewFrame.origin = self.convert(tableViewFrame.origin, to: nil) tableViewFrame.origin.x += 2 + tableXOffset tableViewFrame.origin.y += frame.size.height + 2 + tableYOffset + self.tableView?.frame.origin = tableViewFrame.origin // Avoid animating from (0, 0) when displaying at launch UIView.animate(withDuration: 0.2, animations: { [weak self] in self?.tableView?.frame = tableViewFrame })