You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/02/08 00:54:03 UTC

git commit: Fixes CB-221 - On an orientation change, the orientationchange event not fired on iOS 3 and 4 (it is however fired on iOS 5)

Updated Branches:
  refs/heads/master 6f3c4e8c5 -> b6a08f2cb


Fixes CB-221 - On an orientation change, the orientationchange event not fired on iOS 3 and 4 (it is however fired on iOS 5)


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/b6a08f2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/b6a08f2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/b6a08f2c

Branch: refs/heads/master
Commit: b6a08f2cb0852951226cf16cdafbd5a69db1468c
Parents: 6f3c4e8
Author: Shazron Abdullah <sh...@apache.org>
Authored: Tue Feb 7 15:53:56 2012 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Tue Feb 7 15:53:56 2012 -0800

----------------------------------------------------------------------
 PhoneGapLib/Classes/PGViewController.m |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/b6a08f2c/PhoneGapLib/Classes/PGViewController.m
----------------------------------------------------------------------
diff --git a/PhoneGapLib/Classes/PGViewController.m b/PhoneGapLib/Classes/PGViewController.m
index 0005790..2dbd644 100644
--- a/PhoneGapLib/Classes/PGViewController.m
+++ b/PhoneGapLib/Classes/PGViewController.m
@@ -268,6 +268,33 @@
 }
 
 
+/**
+ Called by UIKit when the device starts to rotate to a new orientation.  This fires the \c setOrientation
+ method on the Orientation object in JavaScript.  Look at the JavaScript documentation for more information.
+ */
+- (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation
+{
+	int i = 0;
+	
+	switch (self.interfaceOrientation){
+		case UIInterfaceOrientationPortrait:
+			i = 0;
+			break;
+		case UIInterfaceOrientationPortraitUpsideDown:
+			i = 180;
+			break;
+		case UIInterfaceOrientationLandscapeLeft:
+			i = -90;
+			break;
+		case UIInterfaceOrientationLandscapeRight:
+			i = 90;
+			break;
+	}
+	
+	NSString* jsCallback = [NSString stringWithFormat:@"window.__defineGetter__('orientation',function(){ return %d; }); PhoneGap.fireEvent('orientationchange', window);",i];
+	[self.webView stringByEvaluatingJavaScriptFromString:jsCallback];    
+}
+
 - (void) createGapView
 {
     CGRect webViewBounds = self.view.bounds;