ios - 按钮和标签在segue后消失

标签 ios swift face-id

我对 swift 和 xcode 很陌生,当我修改应用程序制作时,遇到了一个问题。我正在尝试创建一个按钮,在使用 FaceID 验证我的脸部后切换 View Controller 。这是我到目前为止所拥有的。当我按下按钮时,它确实进行了身份验证,但是当它转到另一个窗口时,标签和按钮就消失了。有人知道为什么吗?任何事情都有帮助。谢谢(:

注意:尽管该按钮不可见,但它仍然有效。我知道这一点是因为当我在 Controller2 中并点击左上角的按钮时,它就完成了操作。问题很简单,就是它不可见。

左边是Controller1,右边是Controller2 Controller1 on left and Controller2 on right

代码:

@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)
            }
        }
    }
}

最佳答案

首先您需要以模态方式呈现 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 设置这些属性,或者在由 performSegue 触发的显示转场类型的 prepareForSegue 中设置它们

第二个不要从第二个 vc 到第一个 vc,您只需要使用

self.dismiss(animated:true,completion:nil)

最后evaluatePolicy的完成在后台线程中运行,因此如果您要使用segue,请考虑这一点

DispatchQueue.main.async {
    self.performSegue(withIdentifier: "toSecondView", sender: self) 
}

关于ios - 按钮和标签在segue后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54485132/

相关文章:

ios - MKMapView可见区域填充

swift - Xcode 7 永久代码覆盖覆盖

ios - 如何检查我的应用程序是否启用了 Face id?

ios - 检测快速双电源按钮按下

ios - UISearchController 中范围栏的定位

ios - 具有 2 路绑定(bind)的 KVO 无限循环

ios - 在 Objective-C 中创建仅对子类可见的属性

swift - 无法将 int 类型的值转换为预期的参数类型 CGGradientDrawingOptions

ios - Touch ID 和 Face ID 的官方图标

ios - 在 IOS 中通过蓝牙连接条码扫描器设备时,默认键盘不出现