[英]Added custom shadow to navigationBar not removing
I have added the custom shadow layer to navigationBar but not able to remove now.我已将自定义阴影层添加到导航栏,但现在无法删除。 Please guide.
请指导。 Below is the code to add:
下面是要添加的代码:
let offset: CGFloat = (self.navigationController?.view.safeAreaInsets.top ?? 20)
shadowView = UIView(frame: CGRect(x: 0, y: -offset,
width: (self.navigationController?.navigationBar.bounds.width)!,
height: (self.navigationController?.navigationBar.bounds.height)! + offset))
shadowView?.backgroundColor = UIColor.white
self.navigationController?.navigationBar.insertSubview(shadowView!, at: 1)
let shadowLayer = CAShapeLayer()
shadowLayer.path = UIBezierPath(roundedRect: shadowView!.bounds, byRoundingCorners: [.bottomLeft, .bottomRight, .topLeft], cornerRadii: CGSize(width: 0, height: 0)).cgPath
shadowLayer.fillColor = UIColor.white.cgColor
shadowLayer.shadowColor = UIColor.darkGray.cgColor
shadowLayer.shadowPath = shadowLayer.path
shadowLayer.shadowOffset = CGSize(width: 2.0, height: 2.0)
shadowLayer.shadowOpacity = 0.8
shadowLayer.shadowRadius = 2
shadowView?.layer.insertSublayer(shadowLayer, at: 0)
For removing i have tried:为了删除我试过:
// self.navigationController?.view.layer.shadowColor = UIColor.clear.cgColor
// self.navigationController?.view.layer.shadowOpacity = 0.0
// self.navigationController?.navigationBar.isTranslucent = true
// for view in navigationController?.navigationBar.subviews ?? [] {
// if view.tag != 0 {
// view.removeFromSuperview()
// }
// }
self.navigationController?.navigationBar.isHidden = true
// self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
// self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
All above statements tried but no success.以上所有语句都尝试过,但没有成功。 Please guide for the same.
请指导相同。 Thanks
谢谢
shadowView.removeFromSuperview()
will do the trick.会做的伎俩。
Are you adding and removing from different files?您是否在不同的文件中添加和删除?
You can use:您可以使用:
shadowView.tag = 1001 navigationController?.navigationBar.subviews.first(where: {$0.tag == 1001})?.removeFromSuperview()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.