我有开发人员正在开发一个IOS应用程序,该应用程序有一个视图中的人网格(一个约会风格的应用程序)。我需要“拉刷新”才能在这个屏幕上工作,即使网格中的用户还没有填充屏幕。如果只有2-4个用户,网格还不够满,还不能滚动。
我的iOS开发人员告诉我,如果网格不是满的和可滚动的,iOS“拉到刷新”就不能工作。这是真的吗?不应该拉刷新工作,无论屏幕是否已满?或者这是怎么容易编程的呢?
谢谢。
发布于 2022-03-09 17:25:19
这是你能得到的最基本的例子.
class ViewController: UIViewController {
let scrollView = UIScrollView()
override func viewDidLoad() {
super.viewDidLoad()
scrollView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(scrollView)
let g = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
// let's constrain the scroll view with 20-points on all sides
// so we can easily distinguish it from the main view
scrollView.topAnchor.constraint(equalTo: g.topAnchor, constant: 20.0),
scrollView.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 20.0),
scrollView.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: -20.0),
scrollView.bottomAnchor.constraint(equalTo: g.bottomAnchor, constant: -20.0),
])
// give it a background color so we can see it
scrollView.backgroundColor = .red
// Add the refresh control
scrollView.refreshControl = UIRefreshControl()
scrollView.refreshControl?.addTarget(self, action: #selector(handleRefreshControl), for: .valueChanged)
}
@objc func handleRefreshControl() {
// do whatever you do to get new content
print("refresh the content")
// let's simulate a 1-second task to get new content
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.scrollView.refreshControl?.endRefreshing()
}
}
}请注意,我们甚至没有将任何子视图添加到滚动视图中,并且刷新控件仍然有效。
发布于 2022-03-09 17:27:26
尝试将alwaysBouncesVertical设置为true。
来自用于UIScrollView的文档(它是UITableView的父文档):
如果将此属性设置为true,且
为true,则允许垂直拖动,即使内容小于滚动视图的界限。默认值为false。
https://developer.apple.com/documentation/uikit/uiscrollview/1619383-alwaysbouncevertical
https://stackoverflow.com/questions/71410488
复制相似问题