简体   繁体   English

在根视图上显示另一个视图时,警报视图中心会更改

[英]Alert view center changes when another view is presented on root view

In the app, I'm showing an alert when there is no internet connection (Showing on root view controller). 在应用程序中,当没有互联网连接时,我会显示警报(在根视图控制器上显示)。 There is a Biometric authentication on the application too. 应用程序上也有Biometric authentication So whenever Biometric page appears (Biometric page also shows on root view controller) on the top of the alertview and removes that from the view, alert view constraints changes and doesn't show in the middle. 所以每当出现生物页面(生物页还显示根视图控制器)上的顶部alertview并删除从视图,警报视图限制变更,也不在中间显示。

Step 1:- 第1步:-

Shows Error message 显示错误信息

在此处输入图片说明

Showing alert Code :- 显示警报代码:-

  func showAlert(title:String, message: String, buttons: [UIAlertAction]) {
    // create the alert
    self.alert.title = title
    self.alert.message = message

    // add an action (button)
    if buttons.count == 0 {
        self.alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
    } else {
        for i in 0...buttons.count-1 {
            self.alert.addAction(buttons[i])
        }
    }
    self.viewController.present(alert, animated: true, completion: nil)
}

Step 2:- 第2步:-

Exit the application and shows the biometric verification view. 退出应用程序并显示生物特征验证视图。

App Delegate File :- 应用代理文件:-

   func applicationDidBecomeActive(_ application: UIApplication) {

    if self.userToken != "" && self.biometricStatus && !UserAccessTemp.isBiometricActive {

        let controller = BiometricCheckViewController.instantiate(fromAppStoryboard: .BiometricCheck)
        if let window = self.window, let rootViewController = window.rootViewController {
            var currentController = rootViewController
            while let presentedController = currentController.presentedViewController {
                currentController = presentedController
            }
            currentController.present(controller, animated: true, completion: nil)
        }

    }

在此处输入图片说明

Step 3:- 步骤3:

Alert View alignment changes after dismiss the biometric verification view 关闭生物特征验证视图后,警报视图对齐方式会发生变化

在此处输入图片说明

So how can I re-center the alert view after the Biometric view dismiss? 那么在关闭生物特征视图后如何重新设置警报视图的中心?

Just put makeKeyAndVisible() to the Biometric view, and it does fix the problem. 只需将makeKeyAndVisible()放到Biometric视图中,即可解决问题。 Thanks to the Deepika's comment. 感谢Deepika的评论。

func applicationDidBecomeActive(_ application: UIApplication) {

    if self.userToken != "" && self.biometricStatus && !UserAccessTemp.isBiometricActive {

        let controller = BiometricCheckViewController.instantiate(fromAppStoryboard: .BiometricCheck)

        let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.rootViewController = UIViewController()
        alertWindow.windowLevel = UIWindowLevelAlert + 1;
        alertWindow.makeKeyAndVisible()
        alertWindow.rootViewController?.present(controller, animated: true, completion: nil)
    }
}

try: 尝试:

func showAlert(title:String, message: String, buttons: [UIAlertAction]) {
    // create the alert
    self.alert.title = title
    self.alert.message = message

    // add an action (button)
    if buttons.count == 0 {
        self.alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
    } else {
        for i in 0...buttons.count-1 {
            self.alert.addAction(buttons[i])
        }
    }

    if var topController = UIApplication.sharedApplication().keyWindow?.rootViewController {
        while let presentedViewController = topController.presentedViewController {
            topController = presentedViewController
        }

        topController.present(alert, animated: true, completion: nil)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我的根视图转到另一个视图时,该视图是否可以更改根视图? - When My root view goes to another View, is there a way for that view to make changes to the root View? 防止在出现警报时显示视图控制器 - Prevent view controllers from being presented when alert is there 当本地显示视图控制器并显示警报时,控件不会变暗 - Controls not dimming when view controller is presented locally and alert displayed 如果出现警报/工作表,则制作 SwiftUI 视图灰度 - Make SwiftUI view grayscale if an alert/sheet is presented 中心视图在另一个视图内 - Center view inside another view 从模态呈现的视图控制器导航到根视图控制器 - Navigate to root view-controller from modally presented view controller 如果以模态呈现另一个视图,则保持 AVSpeechSynthesizer 播放 - Keep AVSpeechSynthesizer playing if another view is presented modally 将视图控制器显示在另一个视图控制器上时,如何获取屏幕截图? - How to get the screenshot when a view controller is presented over another view controller? 如何防止在出现警报时显示视图控制器的 inputAccessoryView? - How to prevent inputAccessoryView of a view controller from being shown when an alert is presented? 单元测试,测试一个视图 controller 是否已经呈现另一个视图 controller - Unit test, to test if a view controller has presented another view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM