Ios 将刷新控件添加到带有页面控件的水平滚动视图

Ios 将刷新控件添加到带有页面控件的水平滚动视图,ios,swift,uiscrollview,uipagecontrol,uirefreshcontrol,Ios,Swift,Uiscrollview,Uipagecontrol,Uirefreshcontrol,我使用的是一个水平滚动视图,带有分页功能,如下所示: 刷新在每个imageView(子视图)中都能正常工作,但刷新指示器仅在我位于第一个imageView时显示 在view Dod load函数中,我将刷新控件添加到scrollView let refreshControl = UIRefreshControl() refreshControl.addTarget(self, action: #selector(refreshOptions(sender:)), for: .valueChang

我使用的是一个水平滚动视图,带有分页功能,如下所示:

刷新在每个imageView(子视图)中都能正常工作,但刷新指示器仅在我位于第一个imageView时显示

在view Dod load函数中,我将刷新控件添加到scrollView

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(refreshOptions(sender:)), for: .valueChanged)
scrollView.refreshControl = refreshControl
// show the page Control if at least two specials are shown
if UrlArray.count > 1{
      pageControl.isHidden = false
}
// add all images to the scrollView
for url in UrlArray {
      // 1.
      frame.origin.x = scrollView.frame.size.width *          CGFloat(origin)
      frame.size = scrollView.frame.size
      // 2.
      let imageView = UIImageView(frame: frame)
      imageView.contentMode = .scaleAspectFit
                
      // get the image for the url in the cache
      if let cachedVersion = cache.object(forKey: url as NSString) {
      imageView.image = cachedVersion.image
      }
      self.scrollView.addSubview(imageView) // add image to        scrollView
                
      // increase origin of next image by one
      // that way next image is horizontally next to the one before
      origin += 1
}
            
// 3.
scrollView.contentSize = CGSize(width: ((scrollView.frame.size.width) * CGFloat(origin)), height: (scrollView.frame.size.height))
scrollView.delegate = self
pageControl.numberOfPages = origin
稍后,我将具有以下功能的子视图添加到scrollView

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(refreshOptions(sender:)), for: .valueChanged)
scrollView.refreshControl = refreshControl
// show the page Control if at least two specials are shown
if UrlArray.count > 1{
      pageControl.isHidden = false
}
// add all images to the scrollView
for url in UrlArray {
      // 1.
      frame.origin.x = scrollView.frame.size.width *          CGFloat(origin)
      frame.size = scrollView.frame.size
      // 2.
      let imageView = UIImageView(frame: frame)
      imageView.contentMode = .scaleAspectFit
                
      // get the image for the url in the cache
      if let cachedVersion = cache.object(forKey: url as NSString) {
      imageView.image = cachedVersion.image
      }
      self.scrollView.addSubview(imageView) // add image to        scrollView
                
      // increase origin of next image by one
      // that way next image is horizontally next to the one before
      origin += 1
}
            
// 3.
scrollView.contentSize = CGSize(width: ((scrollView.frame.size.width) * CGFloat(origin)), height: (scrollView.frame.size.height))
scrollView.delegate = self
pageControl.numberOfPages = origin
以及当用户在图像之间滑动时调用的函数

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        // update page number when view was paged/scrolled
        let pageNumber = scrollView.contentOffset.x / scrollView.frame.size.width
        pageControl.currentPage = Int(pageNumber)
    }
我希望有人能帮助我在每个子视图中显示刷新指示器