iOS 11大型导航栏标题速度出乎意料 [英] iOS 11 large navigation bar title unexpected velocity

查看:133
本文介绍了iOS 11大型导航栏标题速度出乎意料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新应用程序中实现iOS 11本机大型导航栏标题.通过在viewDidLoad()中调用以下函数:

I am trying to implement the iOS 11 native large navigation bar title on my new application. By calling below functions in viewDidLoad():

navigationController?.navigationBar.prefersLargeTitles = true navigationController?.navigationItem.largeTitleDisplayMode = .always

我确实得到了我想要的.

I do get what I desired.

但是,当我开始向上滚动(主视图内唯一的视图是滚动视图)时,滚动使大标题以比实际用手指滚动更快的速度消失. (也就是说,如果我在屏幕上移动2厘米,则滚动视图实际上会滚动2厘米以上,直到大标题缩小到正常"大小为止.)

But, when I start scrolling up (the only view inside the main view is a scroll view), the scrolling makes the large title disappear at a faster velocity than actual scroll with the finger. (that is, if I move 2cm on screen, the scroll view actually scrolls more than 2cm, up until the large title shrinks to the 'usual' size.)

以下是我的应用程序正在滚动的gif图像.我实际上很少移动,它会自动向上滚动那么多.这不同于Apple制造的应用程序(例如,在我的应用程序下方显示的应用程序商店).

The below is the gif of my app being scrolled. I actually move very little, and it automatically scrolls up that much. This differs from the Apple-made applications (the app store for instance, shown below my app).

有人能解决这种异常行为吗?

Does anyone have solution to solving this abnormal behaviour?

根据请求,我正在添加当前的View层次结构.我的代码中没有什么特别的,我只设置了prefersLargeTitles的标题和标志.

Per request, I am adding the current View hierarchy. There isn't anything special in my code, I just set the title and flag for prefersLargeTitles.

推荐答案

我已经调试了几天,并且找到了解决方法.

I have been debugging this for a couple days, and I have found a workaround.

首先,发生了什么事?

UIScrollView在largeTitle中表现不佳.由于导航栏变小的同时在滚动视图上向上滚动,因此滚动次数是实际滚动次数的两倍.

It is the UIScrollView that is not performing well with the largeTitle. Since there is scrolling up on the scroll view at the same time as the navigation bar becoming smaller, there exists twice the scrolling compared to the actual scroll.

我通过有意设置来确认这一点:

I confirmed this by intentionally setting:

scrollView.contentOffset.y = scrollView.contentOffset.y * 0.5

这确实使它可以按需移动.但是,这不能解决整个问题,因为当从大导航栏切换到小导航栏时,它没有产生平稳的过渡.您可以尝试以下代码.

This indeed made it move as desired. But, this couldn't solve the problem entire problem because it did not yield a smooth transition while going from large navigation bar to small navigation bar. You can try the below code out.

if scrollView.contentOffset.y > 0 {
  if self.navigationController!.navigationBar.frame.size.height > 44.0 {
    scrollView.contentOffset.y = scrollView.contentOffset.y * 0.5
  }
}

缓慢滚动时此功能正常,但是当您向下拖动时,它起初动作缓慢(导航高度较大时),然后加快速度.

This worked 'okay' when scrolled slowly, but when you fling downward, it acts slow at first (while navigation height is large), and then speeds up afterwards.

WORKAROUND

简而言之,您不能将UIScrollView与iOS 11大导航栏一起使用.您应该改用UITableViewController.
由于我的视图是由沿垂直方向分布的多个水平UICollectionViews组成的,因此我将UITableView与不同的部分一起使用了情节提要来形成UI. 如果使用UITableViewController,它将按预期执行.
AppStore和所有其他Apple制造的本地应用程序都必须采用这种方式.

Simply put, you CANNOT use UIScrollView with the iOS 11 large navigation bar. You ought to use UITableViewController instead.
Since my view is composed of multiple horizontal UICollectionViews spread along vertically, I used UITableView with different sections to form the UI using storyboard. If you use UITableViewController, it performs as desired.
AppStore and all other Apple-made native apps must do it this way.

这篇关于iOS 11大型导航栏标题速度出乎意料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆