ฉันพยายามขยายมุมมองข้อความเมื่อฉันคลิกปุ่มอ่านเพิ่มเติม มันใช้งานได้บนอุปกรณ์ที่ต่ำกว่า iOS 11 แต่ไม่สามารถขยายได้อย่างราบรื่นมากในเวอร์ชัน iOS 11 ทำไม
เมื่อฉันแตะปุ่มอ่านเพิ่มเติมก็จะเรียกใช้โค้ดนี้
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
}
}
ต่ำกว่าเวอร์ชัน iOS 11
เวอร์ชัน iOS 11
สิ่งที่ฉันได้ลอง
(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
}
}