UIAlertController,文本字段在横向模式下压缩

问题描述 投票:0回答:1

image here

需要创建警报控制器并旋转到横向模式。

我在工作项目中发现了这个问题。在我在空项目中创建带有文本字段的最简单的 UIAlertController 后,发现了同样的问题。看起来像是系统错误?

swift uikit uialertcontroller
1个回答
0
投票

不,这不是系统错误。您似乎可能遇到与第三方库相关的问题。我建议使用本机 iOS 内置功能 UIAlertController 来显示警报,如提供的代码示例所示:

@objc func showAlert() {
    let alertController = UIAlertController(title: "Alert Title", message: "This is a sample alert.", preferredStyle: .alert)

    // Add a text field to the alert
    alertController.addTextField { (textField) in
    textField.placeholder = "Additional Text"
    }

    let okAction = UIAlertAction(title: "OK", style: .default) { (action) in
        // Access the text field's text here if needed
        if let textField = alertController.textFields?.first {
            print("Additional Text: \(textField.text ?? "")")
        }
    }
    alertController.addAction(okAction)

    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
    alertController.addAction(cancelAction)

    present(alertController, animated: true, completion: nil)
}


// Override to allow rotation to landscape mode
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .all
}

// Override to specify the initial interface orientation
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeLeft
}

如果问题仍然存在,查看更多代码或接收有关您所面临问题的其他信息将会很有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.