In my swift 3 project, I'm using UITextFields and UITextViews in my screens and when keyboard appears some of them are overlapped by the keyboard and with the different devices the overlapping views are get differ. For instance, the text fields overlapped in iPhone SE may not overlapped in iPhone 7 plus.
So to scroll up the views how can I determine the views that are gonna overlapped by the keyboard. is there any way of doing this.
I tried to determine the position of the textView in order to determine weather it's overlapped by keyboard or not. but it gives me the same values for smaller and bigger devices. following is what I did.
print(" textfiled position : \(notesTextView.frame)")
print(" X position : \(notesTextView.frame.origin.x)")
print(" Y position : \(notesTextView.frame.origin.y)")
print(" width : \(notesTextView.frame.size.width)")
print(" Height : \(notesTextView.frame.size.height)")
print("Keyboard Height : \(keyboardHeightValue)")
and these are the values i'm getting.
no matter where the UITextView is in the screen and no matter which device am checking once I touch the UITextView it returns the same 108.0 Y value
textfiled position : (23.0, 108.0, 274.0, 150.0)
X position : 23.0
Y position : 108.0
width : 274.0
Height : 150.0
Keyboard Height : 297.0
max Height : 568.0
Screen Height : 320.0
Screen Height : 568.0
I think the way I'm getting the coordinates of the text view may wrong as in my case I need to get the coordinates of the screen.In this case I've taken the position of the view.But as I'm using a table view controller I cannot use below code snippet.
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let position = touch.location(in: self.notesTextView)
location = touch.location(in: self.notesTextView)
print(position.x)
print(position.y)
}
}
how can I get the absolute coordinations of the view.
Thanks and regards!