[英]Scrolling to the top of the UISearchBar in a UITableView
I have a UITableView with a large header. 我有一个带有大标题的UITableView。 At the bottom of the table view is a UISearchBar.
表格视图的底部是UISearchBar。 When
searchBarShouldBeginEditing
fires, I want to scroll UITableView to the top of the screen with the search bar at the top 当
searchBarShouldBeginEditing
触发时,我想将UITableView滚动到屏幕顶部,而搜索栏位于顶部
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)
我尝试了类似的方法来无效
tableView?.scrollRectToVisible(CGRect(x: 0, y: searchBar.frame.minY, width: view.frame.width, height: 400), animated: true)
Would love some help. 希望有所帮助。 Thanks!
谢谢!
You can scroll to the top of the screen by tableView?.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
您可以通过
tableView?.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
滚动到屏幕顶部。
I think what you're looking for is either tableView?.scrollRectToVisible(searchBar.frame, animated: true)
or tableView?.setContentOffset(searchBar.frame.origin, animated: true)
我认为您正在寻找的是
tableView?.scrollRectToVisible(searchBar.frame, animated: true)
或tableView?.setContentOffset(searchBar.frame.origin, animated: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.