使 UIRefreshControl 成为滑动的缩写

Make the UIRefreshControl short for swiping

TableView中使用标准UIRefreshControl时,向下滑动可能会太长,也就是说,我必须将手指几乎拖到屏幕的最底部。

是否可以缩短滑动路径?

var refreshControl = UIRefreshControl()

 @objc func refresh(_ sender: AnyObject) {
    // Refresh anything
 }

 override func viewDidLoad() {
    super.viewDidLoad()
    
    refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
    refreshControl.backgroundColor = UIColor.clear
    TableView.addSubview(refreshControl) 
    
    refresh(view)
 }

预先感谢您的帮助。

试试吧。

    refreshControl.addTarget(self, action: #selector(refreshHande(_:)), for: .valueChanged)
    let ori = tableView.frame
    let temp_frame = CGRect.init(x: ori.origin.x, y: ori.origin.y, width:
    ori.size.width, height: ori.size.height/1.3 )
    tableView.frame = temp_frame
    tableView.addSubview(refreshControl)
    tableView.frame = ori

TableView 有 属性refreshControl。使用以下代码

var refreshControl = UIRefreshControl()

 @objc func refresh(_ sender: AnyObject) {
    // Refresh anything
 }

 override func viewDidLoad() {
    super.viewDidLoad()
    
    refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
    refreshControl.backgroundColor = UIColor.clear

    // tableView is a UITableView outlet 
    tableView.refreshControl = refreshControl
    
 }