简体   繁体   English

向上滚动时隐藏大标题

[英]Hide large title when scrolling up

I have a normal view controller that is embedded in a navigation controller. 我有一个嵌入在导航控制器中的普通视图控制器。 In this view controller, I have a table view that is using the constraints of the safe area. 在这个视图控制器中,我有一个使用安全区域约束的表视图。 (I don't use a table view controller) (我不使用表视图控制器)

The navigation controller is set to prefer large titles and the mode is set to .always. 导航控制器设置为首选大型标题,模式设置为.always。 In beta 2 this worked perfectly, So when I came in the title was large and when I scrolled down it became small (Like the normal one). 在测试版2中,这非常有效,所以当我进入标题时,标题很大,当我向下滚动它变得很小时(就像正常情况一样)。 But since beta 3 this doesn't work anymore. 但是从beta 3开始,这不再适用了。

Anyone know how to turn this back on, or how to make it so when I scroll the table view it will become smaller. 任何人都知道如何重新打开它,或者当我滚动表格视图时如何使它变得更小。 Like the behaviour of all the new iOS 11 apps? 喜欢所有新iOS 11应用程序的行为?

Or is this a bug in the current version of swift 4/iOS 11 but the apps like messenger and settings still work this way. 或者这是当前版本的swift 4 / iOS 11中的一个错误,但是信使和设置之类的应用仍然以这种方式工作。

Thanks in advance. 提前致谢。

对我来说,如果你将故事板中的布尔“首选大标题”设置为true,它将保持很大,如果你通过代码打开它,它按预期工作!

I found a workaround on this site basically, if the tableView (or element that has scroll)is not the first view in your view hierarchy, the large title fails to hide automatically. 我基本上在这个站点找到了一个解决方法,如果tableView(或者有滚动的元素)不是视图层次结构中的第一个视图,则大标题无法自动隐藏。

Example that will NOT work Example that will work 不起作用的 示例将起作用的示例

https://markusbodner.com/2017/10/08/fix-large-navigation-bar-title-not-hiding-on-scroll-in-ios-11/ https://markusbodner.com/2017/10/08/fix-large-navigation-bar-title-not-hiding-on-scroll-in-ios-11/

I added on the view willAppear: 我在视图上添加了willAppear:

        if #available(iOS 11.0, *) {
        navigationController?.navigationBar.prefersLargeTitles = true
    } else {
        // Fallback on earlier versions
    }
(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y > 0) { //20
        [self.navigationController.navigationBar setPrefersLargeTitles:NO];
    } else {   
        [self.navigationController.navigationBar setPrefersLargeTitles:YES];
    }    
}

在IB中为您的导航栏选中“ 首选大标题 ”,或使用:

navigationController?.navigationBar.prefersLargeTitles = true

I'm using a programmatic layout and ran into a similar issue with large titles. 我正在使用程序化布局,并遇到类似的大型游戏问题。 I found the solution here: https://stackoverflow.com/a/46692583/131378 . 我在这里找到了解决方案: https//stackoverflow.com/a/46692583/131378 In viewDidLoad() I had to toggle the largeTitleDisplayMode off and on again. viewDidLoad()我不得不再次关闭largeTitleDisplayMode That was the correct combination that got the large titles working with scrolling: 这是使大型标题与滚动一起工作的正确组合:

self.navigationItem.largeTitleDisplayMode = .never
self.navigationItem.largeTitleDisplayMode = .always

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM