问题描述
我们已经发现了UIKit中似乎有错误的地方,但想在此处发布以查看是否有人遇到此问题或找到了解决方案.
We have found what seems to be a bug in UIKit but wanted to post here to see if anyone else has this problem or found a solution.
我们正尝试使用新的iOS11大标题和悬挂式搜索栏/刷新控件.我们似乎发现了一个问题,其中导航堆栈的根viewController显示了一个较小的显示问题(问题A),但是一旦将另一个viewcontroller推入导航堆栈,则显示变了(问题B):
We're trying to use the new iOS11 large titles and hoisted search bar/refreshcontrol. We seemed to have found a problem where the root viewController of the navigation stack shows a minor display issue (problem A) but once another viewcontroller is pushed onto the navigation stack, the display goes nuts (problem B):
注意事项:
- 该问题在堆栈中的第二个VC而不是第一个VC上更为严重
- refreshControl不是绿色,代码将其设置为您在每个场景上第一次看到它.
- 当您拉动刷新时,refreshControl会向下滑动,不应该这样做
当我们以编程方式在viewDidLoad中执行拉动刷新"以便用户在进入屏幕时可以看到数据正在加载时,这种奇怪的行为似乎仅是一个问题.如果我们删除调用 refreshControl?.beginRefreshing()
的行,则显示是干净的.我已经在示例香草应用程序中重新创建了此问题.这是显示问题的整个视图控制器:
This odd behavior seems to only be a problem when we programmatically do a "pull to refresh" in viewDidLoad so that the user can see that the data is loading when they enter the screen. If we remove the lines that invoke refreshControl?.beginRefreshing()
the display is clean. I've recreated this problem in a sample vanilla app. This is the entirety of the viewcontroller that shows the problem:
import UIKit
class ViewController: UITableViewController {
var tableHeaderSearchController: UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationItem.largeTitleDisplayMode = .always
tableHeaderSearchController = UISearchController(searchResultsController: UITableViewController())
navigationItem.searchController = tableHeaderSearchController
refreshControl?.tintColor = UIColor.green
refreshControl?.backgroundColor = UIColor.clear
refreshControl?.attributedTitle = NSAttributedString(string: "Loading Stuff...", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 17)])
refreshControl?.addTarget(self, action: #selector(refreshPulled), for: .valueChanged)
// Commenting out these 2 lines makes it work fine but you can't see the initial refresh spinner
refreshControl?.beginRefreshing()
refreshPulled()
}
@objc func refreshPulled() {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [refreshControl] in
refreshControl?.endRefreshing()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
这是情节提要.它只是包装在navigationController中的普通tableviewcontroller.3个静态单元格,第二个遍历到相同控制器类型的另一个实例.
Here's the storyboard. It's just a vanilla tableviewcontroller wrapped in a navigationController. 3 static cells, the 2nd one traverses to another instance of the same controller type.
任何想法将不胜感激.我们真的很想采用新外观,但是这些东西使这样做变得非常困难.
Any ideas would be greatly appreciated. We'd really like to adopt the new look but this stuff is making it very hard to do so.
推荐答案
首先,将表视图向上扩展至导航栏下方并确保iOS 11偏移行为正确是至关重要的:
First, it is absolutely crucial that the table view extend up underneath the navigation bar and that is iOS 11 offset behavior be correct:
self.edgesForExtendedLayout = .all
self.tableView.contentInsetAdjustmentBehavior = .always
第二,滚动显示手动刷新时的刷新控件完全由您自己决定,并且计算数量并非易事:
Second, scrolling to show the refresh control when you refresh manually is up to you, and calculating the amount is not at all simple:
self.refreshControl!.sizeToFit()
let top = self.tableView.adjustedContentInset.top
let y = self.refreshControl!.frame.maxY + top
self.tableView.setContentOffset(CGPoint(0, -y), animated:true)
self.refreshControl!.beginRefreshing()
刷新期间 still 栏仍然太大,但是我看不出有什么办法.基本上,苹果已经实现了大标题,并在导航栏中显示了刷新控件,而没有考虑效果或处理由此产生的错误.
The bar still stays too big during the refresh, but I don't see what can be done about that. Basically Apple has implemented large titles and shown the refresh control in the nav bar without thinking through the effects or dealing with the resulting bugs.
这篇关于iOS11上的程序化beginRefreshing()的largeTitles模式存在问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!