ios - iOS 中 View 转换时相机打开

标签 ios swift

import UIKit

class DrawingTransistionViewController: UIViewController,
    UIImagePickerControllerDelegate,
    UINavigationControllerDelegate
{
    override func viewWillAppear(_ animated: Bool)
    {
        let imagePicker = UIImagePickerController()

        imagePicker.delegate = self
        imagePicker.sourceType = .camera

        self.present(imagePicker, animated: true, completion: nil)
    }
}

当前,当代码运行时,它会打开相机,但当您退出相机时,相机会再次打开,因为 View 再次出现。所以我陷入了一个不断的循环。我希望相机在 View 之间转换时仅打开一次。我已经尝试过 viewWillDisappear()、viewDidAppear 和 viewDidDisappear() 但没有取得任何成功。

这是我能找到的唯一有用的文档,但我没有找到太多运气。 https://developer.apple.com/reference/uikit/uiviewcontroller#//apple_ref/doc/uid/TP40006926-CH3-SW18

有什么想法吗?

谢谢

最佳答案

我没有完全理解你的问题。 Uglu 解决方案是只放置 boolen isCameraOpen ,然后在打开相机之前将 aks 打开,第一次打开时只需将该 bool 设置为 true 。为什么不使用 viewDidLoad?

关于ios - iOS 中 View 转换时相机打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41111616/

相关文章:

iphone - 如何将 NSData 字节转换为 NSNumber 或 NSInteger?

ios - 缩放/捏合 UIWebView 中加载的 pdf

ios - 添加更多单元格后,某些表格 View 单元格变得不可见。为什么?

ios - Swift UIView 动画 block 增量错误

ios - 选择器 View 未加载项目

ios - NSOperation 在后台任务结束之前完成

在闪光灯模式下拍照后 iPhone 相机延迟

cocoa-touch - 为什么我的观点相互重叠?

ios - 使用 swift 获取所有 facebook 联系人

Swift 编译器错误 : Segmentation-fault 11 thrown when using type constraints