12

This is a bug that happens frequently, but not always. I have a refresh control added to my UICollectionView. When I refresh, it works perfectly. However, if I half refresh it several times or even do a full refresh, go to another tab in the app, and then return back, when I refresh, the UIRefreshControl appears over part of the UICollectionView. Additionally, instead of starting from zero refresh spinner bars, it starts with all loaded (I've noticied this in other apps such as Mail though, so that much is an OS bug, but in the OS apps, the spinner does not go over the content). Here's an image of the problem: https://www.dropbox.com/s/4qk6qjrdlapsvz0/IMG_0074.JPG Here's how I set up the RefreshController in ViewDidLoad.

refreshControl = [[UIRefreshControl alloc] init];

[refreshControl addTarget:self action:@selector(refresh2)

forControlEvents:UIControlEventValueChanged];

[self.collectionView addSubview:refreshControl];

self.collectionView.alwaysBounceVertical = YES;

Anyone know how to make the spinner go behind the CollectionViewController? Thanks

user1941966
  • 449
  • 5
  • 18

2 Answers2

25

I had this issue as well and figured it out so I thought I would share. what I did was force it to the back of the UICollectionView. I had tried other things like sendSubViewToBack and setting the zIndex of the UICollectionViewCell but it didn't work. However below did work and I tested on iOS 6+:

refreshControl.layer.zPosition = -1;

For iOS 6, add this:

refreshControl.userInteractionEnabled = NO;
Henry T Kirk
  • 961
  • 9
  • 13
  • 1
    Pay attention! if you'll use UIImageView or something as backgroundView, so remember to set the imageView.layer.zPosition to -2 or lower. If you won't do this, the refreshControl will be hidden under the backgroundView. – smartDonkey May 19 '15 at 18:02
  • Wish we could upvote comments, thanks for the tip about backgroundViews. Was driving me insane for hours. – crashoverride777 Apr 23 '18 at 14:10
2

Problem: You start to scroll down and partially reveal the UIRefreshControl, but you don't scroll all the way down to make it start spinning. You navigate to another view (or "minimize" app, send to background) and come back. You scroll a little and the UIRefreshControl shows on top of your collectionview fully loaded, unwelcomed and not spinning.

Solution: You need to endRefreshing on viewWillDissappear and on app being sent to background.

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
    super.viewDidLoad()
    refreshControl.addTarget(self, action: #selector(ViewController.methodNameForRefreshing), forControlEvents: .ValueChanged)
    collectionView.addSubview(refreshControl)
    //or
    tableView.addSubview(refreshControl)

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.willResignActiveNotif), name: UIApplicationWillResignActiveNotification, object: nil)
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    refreshControl.endRefreshing()
}

func willResignActiveNotif(notification: NSNotification) {
    refreshControl.endRefreshing()
}
sweepez
  • 585
  • 1
  • 4
  • 17