I have made solutions that work with scroll and non-scroll views using keyboard notification and a detection of the current first responder, but sometimes I use this trivial solution instead: The simple way is to detect the opening keyboard via the text field delegate's textViewDidBeginEditing:
method and to move the entire view up. The easiest way to do this is with something along the lines of changing self.view.bounds.origin.y
to -100 (or whatever). Use the corresponding textViewShouldEndEditing:
method to set it to the opposite, which is 100 in this case. Changing bounds
is a relative procedure. After changing it the frame is moved but the bounds origin is still zero.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…