gpt4 book ai didi

ios - Swift - 有没有办法在相机处于事件状态时显示 AlertController?

转载 作者:行者123 更新时间:2023-11-28 06:24:07 24 4
gpt4 key购买 nike

<分区>

我正在使用 Swift 3、Xcode 8.2。

我目前有一个应用程序,我可以让用户打开相机拍照。打开相机后,我希望出现一个警告框,为用户提供一些信息。在控制再次返回到相机之前,用户可以单击“完成”。

这是我的代码:

func openCameraAction() {


// Check if the camera is available on the device as a source type
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {

// declare a variable of image picker controller
let imagePicker = UIImagePickerController()

// set its delegate, set its source type
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera

// tell our image picker to not edit a captured picture
// which means that we won’t get the black screen with
// a square frame right after taking a photo.
imagePicker.allowsEditing = false

// present the camera controller, it will show up from the
// bottom of the screen, which is the default iOS animation
// for opening new screens.
self.present(imagePicker, animated: true, completion: nil)


}
}

func displayInstructions() {

let instructionController = UIAlertController(title: "Photo Instructions", message: "Some instruction here", preferredStyle: .alert)

let actionDone = UIAlertAction(title: "Done", style: .cancel) { (action:UIAlertAction) in
//This is called when the user presses the done button.
print("You've pressed the done button");
}


//Add the buttons
instructionController.addAction(actionDone)

//Present the instruction controller
self.present(instructionController, animated: true, completion: nil)
}

我已经尝试在 openCameraAction 中设置 completion 字段来调用方法 displayInstruction 但很快意识到我不能展示东西以嵌套的方式。我相信礼物必须从 Root View Controller 级别发生,对吗?

Attempt to present ... on ... whose view is not in the window hierarchy!

但是,有什么方法可以实现这种效果吗?做一些嵌套礼物?

感谢您的帮助。

编辑

我看了另一个问题,还是有点糊涂。我从其他答案中抓取了一段代码,但很难弄清楚如何将其集成到我的代码中。

        var rootViewController = UIApplication.shared.keyWindow?.rootViewController
if let navigationController = rootViewController as? UINavigationController {
rootViewController = navigationController.viewControllers.first
}
if let tabBarController = rootViewController as? UITabBarController {
rootViewController = tabBarController.selectedViewController
}
rootViewController?.present(alertController, animated: true, completion: nil)

我是否将上述代码包含在 openCameraActiondisplayInstruction 函数中?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com