Fix device orientation unknown in the first time
This commit is contained in:
parent
31562ba067
commit
fa249efac1
@ -37,6 +37,8 @@ namespace irr
|
|||||||
-(BOOL)prefersStatusBarHidden;
|
-(BOOL)prefersStatusBarHidden;
|
||||||
-(BOOL)prefersHomeIndicatorAutoHidden;
|
-(BOOL)prefersHomeIndicatorAutoHidden;
|
||||||
-(void)viewDidAppear:(BOOL)animated;
|
-(void)viewDidAppear:(BOOL)animated;
|
||||||
|
-(void)viewDidLoad;
|
||||||
|
-(void)dealloc;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation HideStatusBarView
|
@implementation HideStatusBarView
|
||||||
@ -44,6 +46,13 @@ namespace irr
|
|||||||
irr::CIrrDeviceiOS* Device;
|
irr::CIrrDeviceiOS* Device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)dealloc
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||||
|
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (id)init: (irr::CIrrDeviceiOS*)device
|
- (id)init: (irr::CIrrDeviceiOS*)device
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
@ -61,6 +70,45 @@ namespace irr
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)orientationChanged:(NSNotification*)note
|
||||||
|
{
|
||||||
|
UIDevice* dev = [UIDevice currentDevice];
|
||||||
|
if (dev == nil)
|
||||||
|
return;
|
||||||
|
|
||||||
|
UIDeviceOrientation orientation = [dev orientation];
|
||||||
|
switch(orientation)
|
||||||
|
{
|
||||||
|
case UIDeviceOrientationLandscapeLeft:
|
||||||
|
Device->setUpsideDown(true);
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationLandscapeRight:
|
||||||
|
Device->setUpsideDown(false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)viewDidLoad
|
||||||
|
{
|
||||||
|
[super viewDidLoad];
|
||||||
|
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserver:self selector:@selector(orientationChanged:)
|
||||||
|
name:UIDeviceOrientationDidChangeNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
|
// On first lanuch orientationChanged returns UIDeviceOrientationUnknown,
|
||||||
|
// so we get the first oritentation from statusBarOrientation
|
||||||
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
||||||
|
// Those values are inverted with UIDeviceOrientation enum for landscape
|
||||||
|
if (orientation == UIInterfaceOrientationLandscapeLeft)
|
||||||
|
Device->setUpsideDown(false);
|
||||||
|
else if (orientation == UIInterfaceOrientationLandscapeRight)
|
||||||
|
Device->setUpsideDown(true);
|
||||||
|
}
|
||||||
|
|
||||||
-(void)viewDidAppear:(BOOL)animated
|
-(void)viewDidAppear:(BOOL)animated
|
||||||
{
|
{
|
||||||
[super viewDidAppear : animated];
|
[super viewDidAppear : animated];
|
||||||
@ -191,34 +239,8 @@ namespace irr
|
|||||||
Focus = true;
|
Focus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)orientationChanged:(NSNotification*)note
|
|
||||||
{
|
|
||||||
if (Device == nil)
|
|
||||||
return;
|
|
||||||
UIDevice* device = note.object;
|
|
||||||
switch(device.orientation)
|
|
||||||
{
|
|
||||||
case UIDeviceOrientationLandscapeLeft:
|
|
||||||
Device->setUpsideDown(true);
|
|
||||||
break;
|
|
||||||
case UIDeviceOrientationLandscapeRight:
|
|
||||||
Device->setUpsideDown(false);
|
|
||||||
break;
|
|
||||||
case UIDeviceOrientationPortrait:
|
|
||||||
case UIDeviceOrientationPortraitUpsideDown:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)runSTK
|
- (void)runSTK
|
||||||
{
|
{
|
||||||
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
addObserver:self selector:@selector(orientationChanged:)
|
|
||||||
name:UIDeviceOrientationDidChangeNotification
|
|
||||||
object:[UIDevice currentDevice]];
|
|
||||||
override_default_params_for_mobile();
|
override_default_params_for_mobile();
|
||||||
struct utsname system_info;
|
struct utsname system_info;
|
||||||
uname(&system_info);
|
uname(&system_info);
|
||||||
|
Loading…
Reference in New Issue
Block a user