我想在推送segue期间将导航栏从半透明更改为透明与动画,但它立即变得透明 .
我扩展了导航控制器:
func setNavigationBarTransparent(transparent:Bool, animated:Bool) {
// If current state of navigation bar is desired state then abort
if barIsTransparent == transparent { return }
// Reset transparency status
barIsTransparent = transparent
// Define transparency
let image: UIImage? = transparent ? UIImage() : nil
// Define animation
let duration: NSTimeInterval = animated ? 0.3 : 0.0
// Style navigation bar
UIView.animateWithDuration(
duration,
animations: {
self.navigationBar.setBackgroundImage(image, forBarMetrics: UIBarMetrics.Default)
self.navigationBar.shadowImage = image
})
}
我在目标视图控制器的 viewWillAppear
中调用 setNavigationBarTransparent(true, animated: true)
. 只要导航栏没有背景图像,条形透明度的转换在segue期间是平滑的,即它背后没有其它视图,因为它是半透明的 . 当我向上滚动集合视图以便在半透明导航栏后面有一个图像时,透明度突然发生,持续时间为零 .
我在这做错了什么?
Update: 刚看到在反向segue期间,条形实际上没有改变它's image from transparent to translucent but the frame slides in from above. So it would be sufficient for the bar'框架在"translucent to transparent" segue期间滑出到上方 .