Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
like image 306
magohamoth Avatar asked Dec 05 '17 09:12

magohamoth


3 Answers

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

like image 106
Li Sim Avatar answered Nov 16 '22 15:11

Li Sim


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.

like image 42
Ravi Raja Jangid Avatar answered Nov 16 '22 16:11

Ravi Raja Jangid


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.

like image 1
JoniVR Avatar answered Nov 16 '22 14:11

JoniVR