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 {
|
||||
DisplayOrientationDefault = 2,
|
||||
DisplayOrientationLandscapeLeft = 1,
|
||||
DisplayOrientationLandscapeRight = 2,
|
||||
DisplayOrientationPortrait = 4
|
||||
DisplayOrientationDefault = UIInterfaceOrientationMaskAll,
|
||||
DisplayOrientationLandscapeLeft = UIInterfaceOrientationMaskLandscapeLeft,
|
||||
DisplayOrientationLandscapeRight = UIInterfaceOrientationMaskLandscapeRight,
|
||||
DisplayOrientationPortrait = UIInterfaceOrientationMaskPortrait,
|
||||
DisplayOrientationPortraitUpsideDown = UIInterfaceOrientationMaskPortraitUpsideDown
|
||||
} DisplayOrientation;
|
@ -31,17 +31,17 @@
|
||||
}
|
||||
|
||||
+ (DisplayOrientation) getDisplayOrientationForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
|
||||
return DisplayOrientationPortrait;
|
||||
} else {
|
||||
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
|
||||
return DisplayOrientationLandscapeLeft;
|
||||
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
|
||||
return DisplayOrientationLandscapeRight;
|
||||
} else {
|
||||
return DisplayOrientationDefault;
|
||||
}
|
||||
}
|
||||
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
|
||||
return DisplayOrientationPortrait;
|
||||
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
|
||||
return DisplayOrientationPortraitUpsideDown;
|
||||
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
|
||||
return DisplayOrientationLandscapeLeft;
|
||||
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
|
||||
return DisplayOrientationLandscapeRight;
|
||||
} else{
|
||||
return DisplayOrientationDefault;
|
||||
}
|
||||
}
|
||||
|
||||
+ (UIInterfaceOrientation) getUIInterfaceOrientationFromString:(NSString*)interfaceOrientation {
|
||||
@ -98,6 +98,14 @@
|
||||
return supported;
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSUInteger)supportedInterfaceOrientations {
|
||||
return supportedOrientations;
|
||||
}
|
||||
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
|
@ -14,7 +14,9 @@
|
||||
#import "GameView.h"
|
||||
#import "TouchPanel+Internal.h"
|
||||
|
||||
@interface GameWindow()
|
||||
@interface GameWindow() {
|
||||
BOOL fakeLandscapeBounds;
|
||||
}
|
||||
|
||||
- (Rectangle*) calculateClientBounds;
|
||||
|
||||
@ -66,9 +68,28 @@
|
||||
}
|
||||
|
||||
- (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;
|
||||
|
||||
if (clientWidth == 0) {
|
||||
@ -77,7 +98,7 @@
|
||||
|
||||
if (clientHeight == 0) {
|
||||
clientHeight = realFrame.size.height * realScale;
|
||||
}
|
||||
}
|
||||
|
||||
float targetAspectRatio = (float)clientWidth/(float)clientHeight;
|
||||
CGRect targetFrame;
|
||||
@ -108,7 +129,19 @@
|
||||
|
||||
// Recalculate client bounds.
|
||||
[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 {
|
||||
@ -142,6 +175,10 @@
|
||||
[clientBounds release];
|
||||
clientBounds = [newClientBounds retain];
|
||||
[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