我有一个ViewController作为弹出窗口来选择UIDatePicker上的日期。但是,当这个弹出窗口打开时,背景会被新的背景颜色覆盖。我尝试选择不透明的颜色,但这不起作用。 我使用UILabel来处理点击并打开一个新的ViewController。
override func viewDidLoad() {
super.viewDidLoad()
let tapDateSelectExpiration = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateExpiration))
let tapDateSelectValidity = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateValidity))
let tapDateSelectOrder = UITapGestureRecognizer(target: self, action: #selector(handleSelectDateOrder))
lblDataPedido.isUserInteractionEnabled = true
lblDataValidade.isUserInteractionEnabled = true
lblDataExpiracao.isUserInteractionEnabled = true
lblDataPedido.addGestureRecognizer(tapDateSelectOrder)
lblDataValidade.addGestureRecognizer(tapDateSelectValidity)
lblDataExpiracao.addGestureRecognizer(tapDateSelectExpiration)
}
@objc func handleSelectDateExpiration(_ sender : UILabel) {
print("handleSelectDateExpiration")
var vcSelectDate = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerSelectDate") as! ViewControllerSelectDate
vcSelectDate.typeDate = "DateExpiration"
self.present(vcSelectDate,animated: true,completion: nil)
}
// Other funcs as above.
MainLayout:
背景不透明的DatePicker布局:
故事板:
答案 0 :(得分:3)
你可以尝试
let vc = self.storyboard?.instantiateViewController(withIdentifier: "dateView") as! dateViewController
vc.delegate = self
vc.providesPresentationContextTransitionStyle = true;
vc.definesPresentationContext = true;
vc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(vc, animated: false, completion: nil)
并选择像这样的透明背景
或在IB