mirror of
https://github.com/thes3m/XNI
synced 2024-12-26 13:26:06 +01:00
Device orientation changes for iOS 6.
git-svn-id: http://xni.googlecode.com/svn/XNI@126 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
parent
0854d703f3
commit
705dc046c7
@ -1,6 +1,9 @@
|
|||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DisplayOrientationDefault = 2,
|
DisplayOrientationDefault = UIInterfaceOrientationMaskAll,
|
||||||
DisplayOrientationLandscapeLeft = 1,
|
DisplayOrientationLandscapeLeft = UIInterfaceOrientationMaskLandscapeLeft,
|
||||||
DisplayOrientationLandscapeRight = 2,
|
DisplayOrientationLandscapeRight = UIInterfaceOrientationMaskLandscapeRight,
|
||||||
DisplayOrientationPortrait = 4
|
DisplayOrientationPortrait = UIInterfaceOrientationMaskPortrait,
|
||||||
|
DisplayOrientationPortraitUpsideDown = UIInterfaceOrientationMaskPortraitUpsideDown
|
||||||
} DisplayOrientation;
|
} DisplayOrientation;
|
@ -31,17 +31,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (DisplayOrientation) getDisplayOrientationForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
+ (DisplayOrientation) getDisplayOrientationForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||||
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
|
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
|
||||||
return DisplayOrientationPortrait;
|
return DisplayOrientationPortrait;
|
||||||
} else {
|
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
|
||||||
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
|
return DisplayOrientationPortraitUpsideDown;
|
||||||
return DisplayOrientationLandscapeLeft;
|
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
|
||||||
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
|
return DisplayOrientationLandscapeLeft;
|
||||||
return DisplayOrientationLandscapeRight;
|
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
|
||||||
} else {
|
return DisplayOrientationLandscapeRight;
|
||||||
return DisplayOrientationDefault;
|
} else{
|
||||||
}
|
return DisplayOrientationDefault;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (UIInterfaceOrientation) getUIInterfaceOrientationFromString:(NSString*)interfaceOrientation {
|
+ (UIInterfaceOrientation) getUIInterfaceOrientationFromString:(NSString*)interfaceOrientation {
|
||||||
@ -98,6 +98,14 @@
|
|||||||
return supported;
|
return supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)shouldAutorotate {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)supportedInterfaceOrientations {
|
||||||
|
return supportedOrientations;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning {
|
- (void)didReceiveMemoryWarning {
|
||||||
// Releases the view if it doesn't have a superview.
|
// Releases the view if it doesn't have a superview.
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
#import "GameView.h"
|
#import "GameView.h"
|
||||||
#import "TouchPanel+Internal.h"
|
#import "TouchPanel+Internal.h"
|
||||||
|
|
||||||
@interface GameWindow()
|
@interface GameWindow() {
|
||||||
|
BOOL fakeLandscapeBounds;
|
||||||
|
}
|
||||||
|
|
||||||
- (Rectangle*) calculateClientBounds;
|
- (Rectangle*) calculateClientBounds;
|
||||||
|
|
||||||
@ -66,9 +68,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) endScreenDeviceChangeWithClientWidth:(int)clientWidth clientHeight:(int)clientHeight {
|
- (void) endScreenDeviceChangeWithClientWidth:(int)clientWidth clientHeight:(int)clientHeight {
|
||||||
CGRect realFrame = [UIScreen mainScreen].applicationFrame;
|
|
||||||
float realScale = [UIScreen mainScreen].scale;
|
|
||||||
|
|
||||||
|
// Before iOS 6.0 the orientation is handled with a different set of functions. Get version so we can act acordingly.
|
||||||
|
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
|
||||||
|
|
||||||
|
CGRect realFrame = [UIScreen mainScreen].applicationFrame;
|
||||||
|
float realScale = [UIScreen mainScreen].scale;
|
||||||
|
|
||||||
|
// Set target view frame to full screen frame to determine orientation.
|
||||||
|
gameViewController.view.frame = realFrame;
|
||||||
|
|
||||||
|
CGRect orientedFrame = gameViewController.view.bounds;
|
||||||
|
NSLog(@"%f, %f", orientedFrame.size.width, orientedFrame.size.height);
|
||||||
|
BOOL deviceIsLandscape = orientedFrame.size.width > orientedFrame.size.height;
|
||||||
|
|
||||||
|
BOOL clientWantsOnlyLandscape = !(gameViewController.supportedOrientations & DisplayOrientationPortrait);
|
||||||
|
|
||||||
|
if (deviceIsLandscape || clientWantsOnlyLandscape) {
|
||||||
|
int height = clientHeight;
|
||||||
|
clientHeight = clientWidth;
|
||||||
|
clientWidth = height;
|
||||||
|
}
|
||||||
|
|
||||||
float realAspectRatio = realFrame.size.width / realFrame.size.height;
|
float realAspectRatio = realFrame.size.width / realFrame.size.height;
|
||||||
|
|
||||||
if (clientWidth == 0) {
|
if (clientWidth == 0) {
|
||||||
@ -77,7 +98,7 @@
|
|||||||
|
|
||||||
if (clientHeight == 0) {
|
if (clientHeight == 0) {
|
||||||
clientHeight = realFrame.size.height * realScale;
|
clientHeight = realFrame.size.height * realScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
float targetAspectRatio = (float)clientWidth/(float)clientHeight;
|
float targetAspectRatio = (float)clientWidth/(float)clientHeight;
|
||||||
CGRect targetFrame;
|
CGRect targetFrame;
|
||||||
@ -108,7 +129,19 @@
|
|||||||
|
|
||||||
// Recalculate client bounds.
|
// Recalculate client bounds.
|
||||||
[clientBounds release];
|
[clientBounds release];
|
||||||
clientBounds = [[self calculateClientBounds] retain];
|
clientBounds = [[self calculateClientBounds] retain];
|
||||||
|
|
||||||
|
if (version < 6) {
|
||||||
|
// If the user requested a landscape backbuffer and our view is still reporting a portrait orientation,
|
||||||
|
// this will change with a later call, so we should manually adjust the (incorrect) bounds for now.
|
||||||
|
// Also, don't switch the orientation if it is already correctly in landscape.
|
||||||
|
if (clientWantsOnlyLandscape && clientBounds.width < clientBounds.height) {
|
||||||
|
int height = clientBounds.height;
|
||||||
|
clientBounds.height = clientBounds.width;
|
||||||
|
clientBounds.width = height;
|
||||||
|
fakeLandscapeBounds = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) initialize {
|
- (void) initialize {
|
||||||
@ -142,6 +175,10 @@
|
|||||||
[clientBounds release];
|
[clientBounds release];
|
||||||
clientBounds = [newClientBounds retain];
|
clientBounds = [newClientBounds retain];
|
||||||
[clientSizeChanged raiseWithSender:self];
|
[clientSizeChanged raiseWithSender:self];
|
||||||
|
} else if (fakeLandscapeBounds) {
|
||||||
|
// Still call client size changed, since the actual screen was in portrait mode before.
|
||||||
|
fakeLandscapeBounds = NO;
|
||||||
|
[clientSizeChanged raiseWithSender:self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user