Search code examples
iosobjective-cuicollectionviewuirefreshcontrol

UIRefreshController goes over the UICollectionView


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


Solution

  • 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;