隐藏导航栏时出现奇怪的动画
Weird animation when hiding the navigation bar
我正在通过嵌入 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
}
此问题仅在引入页面视图控制器后才开始出现。
这是什么原因造成的,我该如何解决?
解决办法原来是在UIPageViewController子类的init中做如下操作:
automaticallyAdjustsScrollViewInsets = false
我不知道为什么会这样,但确实如此。
我早些时候在子视图控制器(代表页面视图控制器的单个页面)中执行此操作,但那没有用。
我正在通过嵌入 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
}
此问题仅在引入页面视图控制器后才开始出现。
这是什么原因造成的,我该如何解决?
解决办法原来是在UIPageViewController子类的init中做如下操作:
automaticallyAdjustsScrollViewInsets = false
我不知道为什么会这样,但确实如此。
我早些时候在子视图控制器(代表页面视图控制器的单个页面)中执行此操作,但那没有用。