透明動畫
只需設置NavigationBar的背景圖片爲一張空圖片便可spa
//設置導航欄透明 self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default) self.navigationController?.navigationBar.shadowImage = UIImage()
在NavigationBar下插入一個view,執行動畫改變這個view的透明度便可。code
let frame = self.navigationController?.navigationBar.frame let alphaView = UIView(frame: CGRect(x: 0, y: -20, width: frame!.size.width, height: frame!.size.height+20)) alphaView.backgroundColor = UIColor.blueColor() alphaView.userInteractionEnabled = false self.navigationController?.navigationBar.insertSubview(alphaView, atIndex: 0)