简体   繁体   English

在表格视图中滚动时,UIActivityIndi​​cator没有向上移动

[英]UIActivityIndicator is not moving up when scrolled in tableview

I have a UITableviewcontroller and a activity indicator added to it. 我有一个UITableviewcontroller和一个活动指示器添加到它。 When ever my table scroll, the indicator also moves up and goes out of bounds. 每当我的表格滚动时,指示器也会向上移动并超出范围。 Instead I want to display indicator even if the table scrolls 相反,即使表格滚动,我也要显示指示器

I checked this post: UIActivityIndicator scrolls with tableView which says I need to use UIViewcontroller instead of Tableviewcontroller. 我检查了这篇文章: UIActivityIndi​​cator使用tableView滚动,它说我需要使用UIViewcontroller而不是Tableviewcontroller。

Since I have many tableviewcontrollers added in application, isnt it possible to scroll indicator along with tableview. 由于我在应用程序中添加了许多tableviewcontrollers,因此无法将指标与tableview一起滚动。

My UIActivityIndicator is helper class across entire application where I control to display and remove spinner 我的UIActivityIndi​​cator是整个应用程序的帮助程序类,我可以在其中控制显示和删除微调器

extension UIViewController {
    class func displaySpinner(onView : UIView) -> UIView {
        let spinnerView = UIView.init(frame: onView.frame)
        spinnerView.backgroundColor = UIColor.init(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)
        let ai = UIActivityIndicatorView.init(activityIndicatorStyle: .whiteLarge)
        ai.startAnimating()
        ai.center = spinnerView.center

        DispatchQueue.main.async {
            spinnerView.addSubview(ai)
            onView.addSubview(spinnerView)
        }

        return spinnerView
    }

    class func removeSpinner(spinner :UIView) {
        DispatchQueue.main.async {
            spinner.removeFromSuperview()
        }
    }
}

You can do it if it's not an extension say the code is inside the tableController and 如果不是扩展名,则说代码在tableController里面,然后

let indicator = UIActivityIndicator()

then use 然后使用

func scrollViewDidScroll(_ scrollView: UIScrollView) {
  // change frame of indicator by scrollview.contentOffset.y
}

You can also extend 您还可以扩展

class MyTableConWithIndicator:UITableViewController {

   let indicator = UIActivityIndicator()

   func scrollViewDidScroll(_ scrollView: UIScrollView) {
     // change y'frame of indicator by scrollview.contentOffset.y
   }
   func addIndicator() {}
   func removeIndicator() ()
}

Then extend from it in every tableController 然后在每个tableController中对其进行扩展

class MyTable:MyTableConWithIndicator {} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM