mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-02-02 22:21:06 +00:00
Fixed the window offset on iOS when resuming an app with a borderless or fullscreen window that has the on-screen keyboard visible.
This commit is contained in:
parent
d603bb30e6
commit
d1372bb92c
|
@ -212,28 +212,12 @@
|
||||||
- (void)keyboardWillShow:(NSNotification *)notification
|
- (void)keyboardWillShow:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
CGRect kbrect = [[notification userInfo][UIKeyboardFrameBeginUserInfoKey] CGRectValue];
|
CGRect kbrect = [[notification userInfo][UIKeyboardFrameBeginUserInfoKey] CGRectValue];
|
||||||
UIView *view = self.view;
|
|
||||||
int height = 0;
|
|
||||||
|
|
||||||
/* The keyboard rect is in the coordinate space of the screen, but we want
|
/* The keyboard rect is in the coordinate space of the screen/window, but we
|
||||||
* its height in the view's coordinate space. */
|
* want its height in the coordinate space of the view. */
|
||||||
#ifdef __IPHONE_8_0
|
kbrect = [self.view convertRect:kbrect fromView:nil];
|
||||||
if ([view respondsToSelector:@selector(convertRect:fromCoordinateSpace:)]) {
|
|
||||||
UIScreen *screen = view.window.screen;
|
|
||||||
kbrect = [view convertRect:kbrect fromCoordinateSpace:screen.coordinateSpace];
|
|
||||||
height = kbrect.size.height;
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* In iOS 7 and below, the screen's coordinate space is never rotated. */
|
|
||||||
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
|
|
||||||
height = kbrect.size.width;
|
|
||||||
} else {
|
|
||||||
height = kbrect.size.height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[self setKeyboardHeight:height];
|
[self setKeyboardHeight:(int)kbrect.size.height];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)keyboardWillHide:(NSNotification *)notification
|
- (void)keyboardWillHide:(NSNotification *)notification
|
||||||
|
@ -243,28 +227,29 @@
|
||||||
|
|
||||||
- (void)updateKeyboard
|
- (void)updateKeyboard
|
||||||
{
|
{
|
||||||
SDL_Rect textrect = self.textInputRect;
|
|
||||||
CGAffineTransform t = self.view.transform;
|
CGAffineTransform t = self.view.transform;
|
||||||
CGPoint offset = CGPointMake(0.0, 0.0);
|
CGPoint offset = CGPointMake(0.0, 0.0);
|
||||||
|
CGRect frame = UIKit_ComputeViewFrame(window, self.view.window.screen);
|
||||||
|
|
||||||
if (self.keyboardHeight) {
|
if (self.keyboardHeight) {
|
||||||
int rectbottom = textrect.y + textrect.h;
|
int rectbottom = self.textInputRect.y + self.textInputRect.h;
|
||||||
int kbottom = self.view.bounds.size.height - self.keyboardHeight;
|
int keybottom = self.view.bounds.size.height - self.keyboardHeight;
|
||||||
if (kbottom < rectbottom) {
|
if (keybottom < rectbottom) {
|
||||||
offset.y = kbottom - rectbottom;
|
offset.y = keybottom - rectbottom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put the offset into the this view transform's coordinate space. */
|
/* Apply this view's transform (except any translation) to the offset, in
|
||||||
|
* order to orient it correctly relative to the frame's coordinate space. */
|
||||||
t.tx = 0.0;
|
t.tx = 0.0;
|
||||||
t.ty = 0.0;
|
t.ty = 0.0;
|
||||||
offset = CGPointApplyAffineTransform(offset, t);
|
offset = CGPointApplyAffineTransform(offset, t);
|
||||||
|
|
||||||
t.tx = offset.x;
|
/* Apply the updated offset to the view's frame. */
|
||||||
t.ty = offset.y;
|
frame.origin.x += offset.x;
|
||||||
|
frame.origin.y += offset.y;
|
||||||
|
|
||||||
/* Move the view by applying the updated transform. */
|
self.view.frame = frame;
|
||||||
self.view.transform = t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setKeyboardHeight:(int)height
|
- (void)setKeyboardHeight:(int)height
|
||||||
|
|
|
@ -273,6 +273,12 @@ UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
|
||||||
|
|
||||||
/* Update the view's frame to account for the status bar change. */
|
/* Update the view's frame to account for the status bar change. */
|
||||||
viewcontroller.view.frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen);
|
viewcontroller.view.frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen);
|
||||||
|
|
||||||
|
#ifdef SDL_IPHONE_KEYBOARD
|
||||||
|
/* Make sure the view is offset correctly when the keyboard is visible. */
|
||||||
|
[viewcontroller updateKeyboard];
|
||||||
|
#endif
|
||||||
|
|
||||||
[viewcontroller.view setNeedsLayout];
|
[viewcontroller.view setNeedsLayout];
|
||||||
[viewcontroller.view layoutIfNeeded];
|
[viewcontroller.view layoutIfNeeded];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue