I'm try to expand the text view when I click the Read More Button.It works on device below iOS 11 but It cannot expand very smooth in iOS 11 version. why?
When I tapped the read more button will run this code.
tableView.beginUpdates()
let txtView = cell2.aboutTxtView!
let txtStr = cell2.aboutTxtView.text!
let btn = cell2.aboutReadBtn!
if self.aboutTag == 0{
let height = getRowHeightFromTextView(strText: txtStr, txtView: txtView)
cell2.aboutTxtView_HeightConstraint.constant = height
self.view.layoutIfNeeded()
btn.setTitle("Show Less", for: .normal)
self.aboutTag = 1
self.aboutHeight = 140.0 + height - 84.0
tableView.endUpdates()
}
else
{
cell2.aboutTxtView_HeightConstraint.constant = 84
self.view.layoutIfNeeded()
btn.setTitle("Read More", for: .normal)
self.aboutTag = 0
self.aboutHeight = 140.0
tableView.endUpdates()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 1
{
return aboutHeight
}
}
Below iOS 11 Version
iOS 11 Version
What i have tried.
(1)
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
(2)
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
if #available(iOS 11, *)
{
self.tableView.contentInsetAdjustmentBehavior = .never
}
}