键盘Y位置错误

时间:2019-03-16 15:37:47

标签: 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具有带有Tap手势和UITextField的UIImageView。当前模式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委托方法:

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。

1 个答案:

答案 0 :(得分:0)

尝试设置应用程序语言:

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