Glitchy animation of UIRefreschControl with large titles for navigation bar

自作多情 提交于 2019-12-05 20:35:39

问题


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.

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)


回答1:


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:




回答2:


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.




回答3:


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.




回答4:


try this code in viewDidLoad:

navigationController?.navigationBar.isTranslucent = true

or set it in storyboard

It helps me.



来源:https://stackoverflow.com/questions/47649785/glitchy-animation-of-uirefreschcontrol-with-large-titles-for-navigation-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!