我在 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()
})
}
此顶部屏幕,当键盘隐藏时:
显示时的键盘框架: (-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/