我有带有自定义视图和UITableView的ViewController。我将自定义视图添加到顶视图,然后设置UIEdgeInsets(top: customView.height, ...)
这样的contentInsets。然后我像这样覆盖scrollViewDidScroll
:
let contentOffset = scrollView.contentOffset
let y = contentOffset.y + customView.height
if y <= 0 {
let newHeight = abs(y) + customView.height
customView.frame = CGRect(
x: 0,
y: 0,
width: UIScreen.main.bounds.size.width,
height: newHeight)
tableView.scrollIndicatorInsets = UIEdgeInsets(top: newHeight, left: 0, bottom: 0, right: 0)
} else {
headerView.frame = CGRect(
x: 0,
y: -y,
width: UIScreen.main.bounds.size.width,
height: UIStatics.avatarCellHeight
)
}
但是当我在表格视图中编辑textView(在文本中添加\ n)时,我跳了customView并遇到了大文本的麻烦(光标的当前可见内容没有移动,并且键盘下的文本消失了)。我的代码有什么问题?