首页 > 解决方案 > 在 Swift 4 中为 Webview 调整图像大小

问题描述

我有一个用 Swift 4 编写的非常简单的 iPhone 应用程序,它基本上只是加载一个 WebView 全屏。所有重要的事情都通过 HTTP 发生并且工作正常。我的网页的一部分允许用户上传照片。经过大约 3 个月的尝试找出为什么在最新的 iOS 上退出工作后,我终于能够修复它。但现在我想在上传图片之前调整它们的大小。我不知道在哪里添加代码来做到这一点,因为我的照片似乎从来没有通过代码。ImagePicker 加载时只运行一次,然后我不知道如何获取照片本身。希望你能帮忙!这是我选择 HTTP 链接以选择图像时运行的内容。

override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
    imagePicker.dismiss(animated: true, completion: nil)

    if viewControllerToPresent is UIImagePickerController {
        viewControllerToPresent.modalPresentationStyle = .overFullScreen
    }
    super.present(viewControllerToPresent, animated: flag, completion: completion)
}

在选择器中选择图像后,它应该调整它们的大小并上传较小的照片。

标签: iosswift

解决方案


推荐阅读