我对swift和xcode还是陌生的,而当我修补应用程序制作时,遇到了一个问题。我正在尝试创建一个在使用FaceID对我的脸进行身份验证后切换视图控制器的按钮。到目前为止,这就是我所拥有的。当我按下按钮时,它会进行身份验证,但是当它锁定到另一个窗口时,标签和按钮就消失了。有谁知道为什么?任何帮助。谢谢(:
注意:即使该按钮不可见,它仍然可以使用。我知道这一点是因为当我进入Controller2并点击左上方按钮时,它完成了操作。问题很简单,就是它不可见。
Controller1在左侧,Controller2在右侧
代码:
@IBAction func faceIDButton(_ sender: Any) {
let context = LAContext()
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "To sign in") { (wasSuccessful, errorInCode) in
if wasSuccessful {
self.performSegue(withIdentifier: "toSecondView", sender: self)
}
}
}
}
答案 0 :(得分:0)
首先,您需要模态呈现vc,并使它的主视图透明,只有完整的部分是您以此识别面部的矩形
let vc = self.storyboard!.instantiateViewController(withIdentifier: "SecondVC") as! SecondVC
vc.delegate = self //to send success of face detection
vc.providesPresentationContextTransitionStyle = true
vc.definesPresentationContext = true
vc.modalPresentationStyle = .overCurrentContext // modally key line
self.present(vc, animated: false, completion: nil)
您还可以为IB中的第二个VC设置这些属性,或在prepareForSegue
触发的performSegue
内将它们设置为表演选择类型
第二不要从第二个vc到第一个vc进行选择,只需使用
self.dismiss(animated:true,completion:nil)
最后完成evaluatePolicy
是在后台线程中运行的,因此,如果您选择segue,请考虑一下
DispatchQueue.main.async {
self.performSegue(withIdentifier: "toSecondView", sender: self)
}