diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bce6af --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +xcuserdata diff --git a/SearchTextField/Classes/SearchTextField.swift b/SearchTextField/Classes/SearchTextField.swift index 2f6ac23..65bcaa4 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() } @@ -299,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 })