![](/img/trans.png)
[英]When My root view goes to another View, is there a way for that view to make changes to the root View?
[英]Alert view center changes when another view is presented on root view
在應用程序中,當沒有互聯網連接時,我會顯示警報(在根視圖控制器上顯示)。 應用程序上也有Biometric authentication
。 所以每當出現生物頁面(生物頁還顯示根視圖控制器)上的頂部alertview
並刪除從視圖,警報視圖限制變更,也不在中間顯示。
第1步:-
顯示錯誤信息
顯示警報代碼:-
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)
}
第2步:-
退出應用程序並顯示生物特征驗證視圖。
應用代理文件:-
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)
}
}
步驟3:
關閉生物特征驗證視圖后,警報視圖對齊方式會發生變化
那么在關閉生物特征視圖后如何重新設置警報視圖的中心?
只需將makeKeyAndVisible()
放到Biometric視圖中,即可解決問題。 感謝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)
}
}
嘗試:
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.