【问题标题】:Weird animation when hiding the navigation bar隐藏导航栏时的奇怪动画
【发布时间】:2017-08-23 19:21:30
【问题描述】:

我正在通过嵌入在 UINavigationController 中的 UIPageViewController 子类(称为 GalleryController)来实现照片库。点击时导航栏隐藏,但动画很奇怪:

https://www.youtube.com/watch?v=9SLF3Nq3uNE

GalleryController 中的代码如下:

  override var navigationItem: UINavigationItem {
    let item = super.navigationItem
    // Access super and add items to it.
    // Don't create a new UINavigationItem instance — that breaks the back button.

    let space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
    space.width = touchSize / 2

    item.rightBarButtonItems = [
      UIBarButtonItem(title: "All Photos", style: .plain, target: self, action: #selector(showAllPhotos)),
      space,
      UIBarButtonItem(title: "Delete", style: .plain, target: self, action: #selector(deletePhoto))
    ]
    return item
  }

这个问题是在引入页面视图控制器之后才开始出现的。

这是什么原因造成的,我该如何解决?

【问题讨论】:

  • 但您的代码与隐藏动画无关
  • 我遇到了类似(但不一样)的问题,this 工作。检查您的 viewWillAppear()。覆盖 func viewWillAppear(_ animated: Bool) {;super.viewWillAppear(animated);navigationController?.setNavigationBarHidden(true, animated: animated);self.navigationItem.hidesBackButton = true;}
  • @Anbu.Karthik 隐藏动画由导航控制器显示。我只是展示了如何配置导航栏,以防它们相关。
  • 好吧,我们成功了
  • 什么意思?

标签: ios animation uinavigationcontroller uinavigationbar uipageviewcontroller


【解决方案1】:

解决方案原来是在 UIPageViewController 子类的 init 中执行以下操作:

automaticallyAdjustsScrollViewInsets = false

我不知道它为什么有效,但确实有效。

我之前在子视图控制器(代表页面视图控制器的单个页面)中执行此操作,但这不起作用。

【讨论】:

    猜你喜欢
    • 2018-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    • 2015-06-14
    • 2020-08-04
    • 1970-01-01
    相关资源
    最近更新 更多