iOS: implement requestWindowOrientation
The application is normally supposed to rotate the content on its
own, but can call requestWindowOrientation to ask the window
manager to do it instead. This way of integrating orientation with
the OS is fragile, because:
1. In some cases, you cannot stop the OS from rotating at all
(tablets).
2. It would be more safe to inform the window manager up-front
which orientations it could rotate into, rather that relying
on a function you call call to force this later on.
3. When the QML application starts, its a bit late to inform
the platform plugin that it supports e.g landscape. If the
OS is in landscape already, the plugin must still assume that
the app operates in portrait (doing rotating on its own) until
requestWindowOrientation is called. This might cause the app
to first start up in portrait, just to rotate into landscape.
On iOS, it seems like we can handle the first two cases. The third
need some more investigation. We should anyway investigate if we
need some adjustment to the Qt API.
Change-Id: I50638b78d469ab70820a787de86a2f1981470786
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
bb10
parent
575d28a6fd
commit
55f0bce094
|
|
@ -40,7 +40,13 @@
|
|||
****************************************************************************/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <QtCore/qnamespace.h>
|
||||
|
||||
@interface QIOSViewController : UIViewController
|
||||
@interface QIOSViewController : UIViewController {
|
||||
@public
|
||||
bool m_shouldAutorotate;
|
||||
}
|
||||
|
||||
-(bool)rotateToDeviceOrientation;
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -43,12 +43,32 @@
|
|||
|
||||
@implementation QIOSViewController
|
||||
|
||||
- (BOOL)shouldAutorotate
|
||||
-(id)init
|
||||
{
|
||||
return NO;
|
||||
self = [super init];
|
||||
if (self) {
|
||||
m_shouldAutorotate = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSUInteger)supportedInterfaceOrientations
|
||||
-(bool)rotateToDeviceOrientation
|
||||
{
|
||||
if ([UIViewController respondsToSelector:@selector(attemptRotationToDeviceOrientation)]) {
|
||||
m_shouldAutorotate = YES;
|
||||
[UIViewController attemptRotationToDeviceOrientation];
|
||||
m_shouldAutorotate = NO;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
-(BOOL)shouldAutorotate
|
||||
{
|
||||
return m_shouldAutorotate;
|
||||
}
|
||||
|
||||
-(NSUInteger)supportedInterfaceOrientations
|
||||
{
|
||||
// We need to tell iOS that we support all orientations in order to set
|
||||
// status bar orientation when application content orientation changes.
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ public:
|
|||
|
||||
void setWindowState(Qt::WindowState state);
|
||||
void handleContentOrientationChange(Qt::ScreenOrientation orientation);
|
||||
Qt::ScreenOrientation requestWindowOrientation(Qt::ScreenOrientation orientation);
|
||||
|
||||
GLuint framebufferObject(const QIOSContext &context) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include "qiosscreen.h"
|
||||
#include "qiosapplicationdelegate.h"
|
||||
#include "qiosorientationlistener.h"
|
||||
#include "qiosviewcontroller.h"
|
||||
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
|
||||
|
|
@ -257,6 +258,22 @@ void QIOSWindow::handleContentOrientationChange(Qt::ScreenOrientation orientatio
|
|||
[[UIApplication sharedApplication] setStatusBarOrientation:uiOrientation animated:NO];
|
||||
}
|
||||
|
||||
Qt::ScreenOrientation QIOSWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
|
||||
{
|
||||
if (!m_view.window)
|
||||
return Qt::PortraitOrientation;
|
||||
UIViewController *viewController = m_view.window.rootViewController;
|
||||
if (!viewController || [viewController isKindOfClass:[QIOSViewController class]] == false) {
|
||||
return convertToQtOrientation(viewController.interfaceOrientation);
|
||||
} else {
|
||||
QIOSViewController *qiosViewController = static_cast<QIOSViewController *>(viewController);
|
||||
if ([qiosViewController rotateToDeviceOrientation])
|
||||
return orientation;
|
||||
else
|
||||
return convertToQtOrientation(viewController.interfaceOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
GLuint QIOSWindow::framebufferObject(const QIOSContext &context) const
|
||||
{
|
||||
static GLuint framebuffer = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue