Glitchy animation of UIRefreshControl with large titles or searchbar in navigation bar
Asked Answered
S

4

16

I have a controller embedded in a navigation controller with Large Titles and a UIRefreshControl. When I pull-to-refresh on my tableView, the animation of the activity indicator is very glitchy.

enter image description here

I don't know if I have a bad behaviour in my code ?

tableView.refreshControl = UIRefreshControl()
tableView.refreshControl?.addTarget(self, action: #selector(downloadData), for: .valueChanged)
Sontich answered 5/12, 2017 at 9:9 Comment(5)
Same issue. Li Sim's answer fixes 50%. Now my issue is refresh control is triggered more than once at pull to refresh :(Skirling
Did you ever find a solution for this? I'm still having this issue :(Adventitious
No :( but I will post it as soon as I have it if I rework on the issue!Sontich
This is also a problem with normal (not large) titles, but with a search bar combined with a refresh control. Ran into this on iOS 13. The problem was caused by translucent=false, and was fixed by extendedLayoutIncludesOpaqueBarsGibeon
There is no description of "glitchy" in the question. My experience was: spinner presented, but almost immediately disappeared. When, later, I called endRefreshing() the navigation bar remained at its larger size - it didn't collapse until I scrolled the tableview back up.Gibeon
S
9

If your have set your navigation bar translucency appearance to false, then you need to include the following code in your view controller to handle opaque bars. Also, in storyboard, the tableView has to have the top constraint extended to the Superview. Somehow, I don't know why there's no proper documentation indicating as such but it seems to resolve the glitchy animation.

self.extendedLayoutIncludesOpaqueBars = true

Adding into this, I find this setup to be working well at the moment with the help of the link that @ Ravi Raja Jangid posted. I'm not sure if it's because tableview is now attached to the Superview (extending status bar) or has the iOS version upgrade fixed the buggy issue.

Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7.

SearchController:

private lazy var searchController: UISearchController = {
        let searchController = UISearchController(searchResultsController: nil)
        searchController.searchResultsUpdater = self
        searchController.obscuresBackgroundDuringPresentation = false
        searchController.hidesNavigationBarDuringPresentation = false
        self.definesPresentationContext = false
        return searchController
    }()

viewDidLoad()

self.navigationItem.hidesSearchBarWhenScrolling = false
self.navigationItem.searchController = self.searchController
self.navigationController?.navigationBar.isTranslucent = false
self.extendedLayoutIncludesOpaqueBars = true

Storyboard Setup: TableView top constraint must be to Superview

Sherr answered 2/2, 2018 at 10:38 Comment(0)
P
3

Only put the below shown code in -(void)viewDidLoad method :

-(void)viewDidLoad 
{
    self.extendedLayoutIncludesOpaqueBars = true;
    self.navigationController.navigationBar.translucent=false;
}

And make sure the property of navigation bar translucent set to be false because if its true then Navigation bar need its underneath content to reflect the translucent effect. For more details you may refer this post

Some time it may happen because of breaking some constraints rule by the some component (views) in Controller.

Pilfer answered 7/8, 2018 at 11:28 Comment(0)
P
1

As far as I can remember, I'd recommend you to use a UITableViewController instead of a UIViewController with a UITableView embedded in it.

The big advantage of this is that UITableViewController already has a lot of these things built in by default (like the UIRefreshControl), so you don't have to deal with a lot of these bugs, adding a UIRefreshControl to a UIViewController manually is always a bit buggy for me.

In general, you'd want to try and use the UITableViewController where possible, the only places where you can't use it is where the UITableView can't take up the whole UIViewController.

Check out the documentation on UITableViewController for more info.

edit: Also, it would be useful if you could post your code that's actually fetching the data, because quite often that can be the issue too.

Phyllous answered 7/8, 2018 at 12:28 Comment(0)
D
-1

try this code in viewDidLoad:

navigationController?.navigationBar.isTranslucent = true

or set it in storyboard

It helps me.

Delorasdelorenzo answered 27/3, 2018 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.