ios - Scrolling to the top of the UISearchBar in a UITableView
问题描述
I have a UITableView with a large header. At the bottom of the table view is a UISearchBar. When searchBarShouldBeginEditing
fires, I want to scroll UITableView to the top of the screen with the search bar at the top
I tried something like this to no avail tableView?.scrollRectToVisible(CGRect(x: 0, y: searchBar.frame.minY, width: view.frame.width, height: 400), animated: true)
Would love some help. Thanks!
解决方案
您可以通过以下方式滚动到屏幕顶部
tableView?.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
我认为您正在寻找的是tableView?.scrollRectToVisible(searchBar.frame, animated: true)
或者tableView?.setContentOffset(searchBar.frame.origin, animated: true)
推荐阅读
- ios - 使用 detox 测试 e2e 无法启动 iPhone 模拟器,而是启动 Apple TV
- powerbi - 波兰邮政编码的填充地图显示了整个国家
- java - Java-Collection:这个非常具体的案例要使用什么集合?
- r - 在单区混合模型中绘制多个随机效应
- android - 使用时区设置当前时间
- php - WordPress AJAX 多数据参数
- qgis - qgis - 创建层 - 看不到纬度值
- c# - ACR1252 NFC读写器序列号
- webrtc - webrtc mips build:为什么 rtc_executable build 生成 ELF 32 位 LSB 共享对象而不是 ELF 32 位 LSB 可执行文件
- ios - 如果 TextField 为空,则禁用按钮