当使用大标题无法正常工作时,iOS 11会滚动到顶部(iOS 11 scroll to top when using large titles doesn't work properly)
当使用大标题并点击状态栏滚动到
UIScrollView
或UITableView
(也可能是UICollectionView
,尚未测试过)的UICollectionView
,它总是有点过分。我在我的
TableView
上启用了刷新功能,当点击状态栏时,它就会像这样出现,并保持这种状态直到我点击屏幕。我在另一个
ViewController
有一个ScrollView
,如果我点击状态栏,它也会滚动得太远,导致导航栏太高。 当我点击某处或滚动一点点时,这也会恢复正常。这也只发生在我激活大标题时,使用普通标题一切正常。
任何想法如何解决这一问题?
如何重新创建:
- 使用导航控制器和带有
TableView
的UIViewController
创建一个新项目。- 设置导航控制器以选择较大的标题。 打开半透明。 在
UIViewController
上设置标题- 在
TableView
上设置约束以固定到ViewController
的边缘- 在
ViewController
为TableView
创建出口- 实现委托并设置多个行,例如100
- 启动应用程序
- 向下滚动,使大标题成为普通标题
- 点击状态栏,使
tableView
滚动到顶部现在标题不在应该的位置,如果你现在向上或向下滚动一点,它就会回到正常位置。
ViewController
代码:import UIKit class ViewController: UIViewController { @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() tableView.delegate = self tableView.dataSource = self } } extension ViewController: UITableViewDelegate, UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 100 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell", for: indexPath) return cell } }
When using large titles and tapping the status bar to scroll to the top of a
UIScrollView
orUITableView
(probably alsoUICollectionView
, haven't tested this) it always goes a little too far.I have refresh enabled on my
TableView
and when tapping the status bar it appears like this and stays that way until I tap the screen.I have a
ScrollView
in anotherViewController
and if I tap the status bar there it also scrolls a little bit too far, making the navigation bar too tall. This also returns to normal when I tap somewhere or scroll a tiny bit.After I tapped the status bar:
This also only happens when I have large titles activated, using normal titles everything works as it should.
Any ideas how to fix this?
How to recreate:
- Create a new project with a navigation controller and a
UIViewController
with aTableView
inside.- Set navigation controller to prefer large titles. Turn translucent off. Set title on
UIViewController
- Set constraints on
TableView
to pin to the edges of theViewController
- Create outlet for
TableView
in theViewController
- Implement delegates and set a number of rows, for example 100
- Launch app
- Scroll down so the large title becomes a normal title
- Tap status bar so the
tableView
scrolls to the topNow the title is not at the position it should be, if you now scroll a tiny bit up or down it snaps back to the normal position.
ViewController
code:import UIKit class ViewController: UIViewController { @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() tableView.delegate = self tableView.dataSource = self } } extension ViewController: UITableViewDelegate, UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 100 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell", for: indexPath) return cell } }
最满意答案
好吧,我找到了问题发生的原因,但不知道如何解决这个问题。
如果您在导航栏半透明设置为关闭的情况下使用大标题和UITableViewController,则会出现问题。 当你把问题变成半透明时,问题就消失了。
如果你在普通的UIViewController中使用TableView,总是会出现问题。
编辑
如果您使用的是半透明导航栏,则会发现设置“extendedLayoutIncludesOpaqueBars = true”会解决问题!
Okay so I found why the problem occurs, but not how to fix it in that exact scenario.
If you're using large titles and a UITableViewController with the navigation bar translucency set to off the problem will occur. When you turn translucent back on the problem goes away.
If you're using a TableView in a normal UIViewController the problem always occurs.
Edit
Turns out setting "extendedLayoutIncludesOpaqueBars = true" fixes the problem if you're using a translucent navigation bar!
Similar question: UIRefreshControl() in iOS 11 Glitchy effect
相关问答
更多-
好消息! 我刚才发现,如果我在故事板上将“大标题”设置为“从不” ,然后通过代码进行设置,那么它可以工作: - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic; } 就像Apple忘记处理导航项目通过Interface Builder设置的largeTitleDisplayMo ...
-
在iOS7中,整个屏幕UITableView和UIScrollView组件默认情况下,调整内容和滚动指示符插入,以使一切正常。 但是,正如您注意到,CGPointZero不再代表将您带到视觉“顶部”的内容偏移量。 改用: self.tableView.contentOffset = CGPointMake(0, 0 - self.tableView.contentInset.top); 在这里,您不必担心如果您有段或行。 您也不会将Table View定位到第一行,然后想知道为什么它不显示所有非常高的表头 ...
-
在正确对齐锚点后,避免自动滚动到顶部(Avoid auto scrolling to the top after aligning with an anchor properly)[2022-06-07]
经过大量的测试,结果发现Safari(6.0.4)是导致问题的原因。 经过不同浏览器的测试,Safari是唯一一个遇到锚点问题的浏览器。 使用Safari,javascript和主播之间存在某种形式的冲突,尽管它不受我的控制。 我已将所有脚本更新到最新版本。 浏览器测试,所有最新版本: Safari(Windows)Firefox(Windows)Chrome(Windows)IE 9 Firefox(OS X最新)Chrome(OS X最新)Safari(iOS)Chrome(iOS)Safari(OS ... -
我想你找不到明确解决问题的方法。 您要求的是导航栏内部的一部分,不向用户公开。 但是,我想我可以为你提供一个解决方法。 要理解这一点,我们来看一下视图调试器中的导航栏(启用了大型标题)。 正如您在下图所示,有一个额外的视图,包含特定视图控制器的大标题。 当您不支持大型标题时,此视图不存在。 基本上,你想知道的是那个视图的高度。 这是我提出的解决方案/解决方法 extension UINavigationBar { var lagreTitleHeight: CGFloat { let ...
-
滚动到顶部问题(Scroll to top problems)[2022-09-24]
这应该工作: $("#tapeHD").click(function() { $("html, body").animate({scrollTop: $('body').offset().top }, 'slow'); DEMO I'm completely STUPID, I wrote the code in the wrong js file (that file wasn't linked...) I'm so sorry, dudes, thanks for your ... -
不要在Interface Builder / Storyboard中设置关于大标题的任何内容, 只能在代码中设置 。 这对我有效。 因此,在故事板的导航栏中,取消选中“首选大标题”。 在你的视图控制器中: self.navigationController?.navigationBar.prefersLargeTitles = true Don't set anything regarding Large Titles in Interface Builder / Storyboard, only in c ...
-
用这个 : tableView.setContentOffset(CGPoint(x: 0, y: -141), animated: true) 这里的141是带有大标题和状态栏的导航栏的大小(97点+44点)。 Use this : tableView.setContentOffset(CGPoint(x: 0, y: -141), animated: true) Here 141 is the size of the navigation bar with large titles and the ...
-
当使用大标题无法正常工作时,iOS 11会滚动到顶部(iOS 11 scroll to top when using large titles doesn't work properly)[2023-02-04]
好吧,我找到了问题发生的原因,但不知道如何解决这个问题。 如果您在导航栏半透明设置为关闭的情况下使用大标题和UITableViewController,则会出现问题。 当你把问题变成半透明时,问题就消失了。 如果你在普通的UIViewController中使用TableView,总是会出现问题。 编辑 如果您使用的是半透明导航栏,则会发现设置“extendedLayoutIncludesOpaqueBars = true”会解决问题! 类似的问题: UIRefreshControl()在iOS 11中有一些 ... -
当页面从底部点击时,jQuery数据表滚动到顶部(jquery datatables scroll to top when pages clicked from bottom)[2022-01-17]
更新 。 原来的答案是针对1.9.x. 在dataTables 1.10.x中更容易: table.on('page.dt', function() { $('html, body').animate({ scrollTop: $(".dataTables_wrapper").offset().top }, 'slow'); }); 演示 - > http://jsfiddle.net/wq853akd/ 另外,如果您使用的是引导版数据表,您可能会注意到,在使用修补程序时,页面在滚动到顶部 ... -
那么,我在这里的行动有点晚了,但为了将来的参考: 对于iOS 10+(足够,因为11中引入了增长的navigationBars),您可以使用 scrollView.perform(NSSelectorFromString("_scrollToTopIfPossible:"), with: true) 这是私有API 。 我搜索了几个小时并尝试了很多东西,但最终这是唯一有用的东西。 请注意,WhatsApp似乎正在使用相同的方法。 也许他们与Apple有特殊的交易或隐藏api呼叫( 咳嗽 base64 咳嗽 ...