ios - 键盘 Y 位置错误

标签 ios swift

我在 ViewController 中添加了我的 CustomView。我使用这个方法:

func showCreateProfileAlert() {
            let screenHeight = UIWindow().screen.bounds.height
            let screenWidth = UIWindow().screen.bounds.width

            //Alert
            let alert = CreateNewJobProfile.instanceFromNib()
            let height = (self.view.bounds.height + 94) - self.view.bounds.height
            let frame = CGRect(x: 8, y: height, width: self.view.bounds.width - 16, height: 200)
            alert.frame = frame
            self.createProfileView = alert

            UIView.animate(withDuration: 0.2) {
                self.view.addSubview(alert)
            }
    }

CustomView 具有带有点击手势的 UIImageView 和 UITextField。当前模态UIImageViewController的手势调用方法:

func photoFromLibrary() {
        imagePicker.allowsEditing = true
        imagePicker.sourceType = .photoLibrary
        imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
        self.present(self.imagePicker, animated: true, completion: nil)   
    }

键盘位于底部屏幕的右侧位置。 如果关闭 UIImagePickerController,键盘的 Y 位置错误。

UIImagePickerController委托(delegate)方法:

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        self.dismiss(animated: true, completion: {
           //Create and show alert again
           self.showCreateProfileAlert()
        })
    }

此顶部屏幕,当键盘隐藏时:

enter image description here

显示时的键盘框架: (-207.0、-271.0、414.0、271.0)

更新

我用 UIImageView 和 UITextfield 创建了简单的 UIViewController 并再次遇到了这个错误。 我只是展示模态 UIImagePickerController。

最佳答案

尝试设置应用程序语言:

Go to Product > Scheme > Edit Scheme... or press cmd + Y.

关于ios - 键盘 Y 位置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55198522/

相关文章:

ios - 如何从 UIStoryboardPopoverSegue 获取由 UIPopoverController 包装的 View Controller ?

ios - 在 Interface Builder 中更改导航栏标题字体

ios - 使用 Alamofire 和 EVReflection 的 JSON POST 请求

ios - 如何在 iOS 的共享首选项中保存 cookie?

swift - 使用 Swift 从 Parse 中检索图像

ios - 无法检测到内存泄漏Xcode

ios - 无法在 iPad + Swift 3 上使用蓝牙扬声器进行录音

ios - iPhone - 需要一些关于 EXC_BAD_ACCESS 的帮助,这让我发疯(包括完整的源代码)

ios - 如何通过 SceneKit 和模型 I/O 在 .OBJ 3d 模型上应用 .MTL 文件

swift - MTKView : Type of expression is ambiguous without more context on commandBuffer. 存在