我在TabBarController中有一个ViewController,我想在ViewController中添加一个BlurView,它也会影响TabBarController,如何做到这一点。
如果我使用此代码:
func presentBlurView() {
blurEffect = UIBlurEffect(style: blurEffectStyle)
blurView1 = UIView()
blurView1!.frame = self.view.frame
blurView1!.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.5)
self.view.addSubview(blurView1!)
blurView1!.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activateConstraints([
blurView1!.leftAnchor.constraintEqualToAnchor(self.view.leftAnchor, constant: 0),
blurView1!.topAnchor.constraintEqualToAnchor(self.view.topAnchor, constant: 0),
blurView1!.rightAnchor.constraintEqualToAnchor(self.view.rightAnchor,constant:0),
blurView1!.bottomAnchor.constraintEqualToAnchor(self.view.bottomAnchor,constant:0)
])
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissProjectDetailViewRightSight:")
tapGestureRecognizer.cancelsTouchesInView = false
blurView1!.addGestureRecognizer(tapGestureRecognizer)
}
它只显示ViewController的整个视图,而不是对TabBarController的影响。但如果我这样改变:
UIApplication.sharedApplication().keyWindow?.addSubview(blurView1!)
它适用于TabBarController,但在这种情况下,很难处理某些事情。反正有没有解决这个问题。任何帮助将不胜感激。
答案 0 :(得分:0)
你可以试试这个:
self.tabBarController?.view.addSubview(blurView1!)