@@ -212,28 +212,12 @@ - (void)hideKeyboard
212
212
- (void )keyboardWillShow : (NSNotification *)notification
213
213
{
214
214
CGRect kbrect = [[notification userInfo ][UIKeyboardFrameBeginUserInfoKey] CGRectValue ];
215
- UIView *view = self.view ;
216
- int height = 0 ;
217
-
218
- /* The keyboard rect is in the coordinate space of the screen, but we want
219
- * its height in the view's coordinate space. */
220
- #ifdef __IPHONE_8_0
221
- if ([view respondsToSelector: @selector (convertRect:fromCoordinateSpace: )]) {
222
- UIScreen *screen = view.window .screen ;
223
- kbrect = [view convertRect: kbrect fromCoordinateSpace: screen.coordinateSpace];
224
- height = kbrect.size .height ;
225
- } else
226
- #endif
227
- {
228
- /* In iOS 7 and below, the screen's coordinate space is never rotated. */
229
- if (UIInterfaceOrientationIsLandscape ([UIApplication sharedApplication ].statusBarOrientation )) {
230
- height = kbrect.size .width ;
231
- } else {
232
- height = kbrect.size .height ;
233
- }
234
- }
235
215
236
- [self setKeyboardHeight: height];
216
+ /* The keyboard rect is in the coordinate space of the screen/window, but we
217
+ * want its height in the coordinate space of the view. */
218
+ kbrect = [self .view convertRect: kbrect fromView: nil ];
219
+
220
+ [self setKeyboardHeight: (int )kbrect.size.height];
237
221
}
238
222
239
223
- (void )keyboardWillHide : (NSNotification *)notification
@@ -243,28 +227,29 @@ - (void)keyboardWillHide:(NSNotification *)notification
243
227
244
228
- (void )updateKeyboard
245
229
{
246
- SDL_Rect textrect = self.textInputRect ;
247
230
CGAffineTransform t = self.view .transform ;
248
231
CGPoint offset = CGPointMake (0.0 , 0.0 );
232
+ CGRect frame = UIKit_ComputeViewFrame (window, self.view .window .screen );
249
233
250
234
if (self.keyboardHeight ) {
251
- int rectbottom = textrect. y + textrect .h ;
252
- int kbottom = self.view .bounds .size .height - self.keyboardHeight ;
253
- if (kbottom < rectbottom) {
254
- offset.y = kbottom - rectbottom;
235
+ int rectbottom = self. textInputRect . y + self. textInputRect .h ;
236
+ int keybottom = self.view .bounds .size .height - self.keyboardHeight ;
237
+ if (keybottom < rectbottom) {
238
+ offset.y = keybottom - rectbottom;
255
239
}
256
240
}
257
241
258
- /* Put the offset into the this view transform's coordinate space. */
242
+ /* Apply this view's transform (except any translation) to the offset, in
243
+ * order to orient it correctly relative to the frame's coordinate space. */
259
244
t.tx = 0.0 ;
260
245
t.ty = 0.0 ;
261
246
offset = CGPointApplyAffineTransform (offset, t);
262
247
263
- t.tx = offset.x ;
264
- t.ty = offset.y ;
248
+ /* Apply the updated offset to the view's frame. */
249
+ frame.origin .x += offset.x ;
250
+ frame.origin .y += offset.y ;
265
251
266
- /* Move the view by applying the updated transform. */
267
- self.view .transform = t;
252
+ self.view .frame = frame;
268
253
}
269
254
270
255
- (void )setKeyboardHeight : (int )height
0 commit comments