-
25 Feb 2011 10:42 PM #11
-
15 Mar 2011 11:05 PM #12
PhoneGap example in PhoneGapViewController.m
PhoneGap example in PhoneGapViewController.m
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2005-2010, Nitobi Software Inc.
*/
#import "PhoneGapViewController.h"
#import "PhoneGapDelegate.h"
@implementation PhoneGapViewController
@synthesize supportedOrientations, webView;
- (id) init
{
if (self = [super init]) {
// do other init here
}
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
{
BOOL autoRotate = [self.supportedOrientations count] > 1; // autorotate if only more than 1 orientation supported
if (autoRotate)
{
if ([self.supportedOrientations containsObject:
[NSNumber numberWithInt:interfaceOrientation]]) {
return YES;
}
}
return NO;
}
/**
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)willRotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration: (NSTimeInterval)duration {
double i = 0;
switch (toInterfaceOrientation){
case UIInterfaceOrientationPortrait:
i = 0;
break;
case UIInterfaceOrientationPortraitUpsideDown:
i = 180;
break;
case UIInterfaceOrientationLandscapeLeft:
i = 90;
break;
case UIInterfaceOrientationLandscapeRight:
i = -90;
break;
}
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"navigator.orientation.setOrientation(%f);", i]];
////// trigger orientationchange inUIWebView for SenchaTouch
[webView stringByEvaluatingJavaScriptFromString:@"var e = document.createEvent('Events'); e.initEvent('orientationchange', true, false); document.dispatchEvent(e); "];
}
- (void) setWebView:(UIWebView*) theWebView {
webView = theWebView;
}
@end
-
17 Mar 2011 12:17 AM #13
-
22 Mar 2011 3:57 AM #14
Sorry, but I can't setup this code in my project, maybe 'cause I don't know objective-c?
I received an error because supportedOrientations e webView are not defined. Where I must define them? And what type are these vars?
thanks
-
18 Apr 2011 5:13 PM #15
There has been a fix committed for this in github...
https://github.com/phonegap/phonegap...comment-348170
but it does not quite work because it only calls window.onorientationchange() and does not create the event as above
-
5 Aug 2011 4:08 AM #16
Thanks for the code partly solved my problem but Ext.Viewport.orientation always returns 'Portrait' even if its not.
Any idea?
Thanks
-
5 Aug 2011 4:58 AM #17
Solved
Code:- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ switch (toInterfaceOrientation) { case UIDeviceOrientationPortrait: [webView stringByEvaluatingJavaScriptFromString:@"window.__defineGetter__('orientation',function(){return 0;});window.onorientationchange();"]; break; case UIDeviceOrientationLandscapeLeft: [webView stringByEvaluatingJavaScriptFromString:@"window.__defineGetter__('orientation',function(){return 90;});window.onorientationchange();"]; break; case UIDeviceOrientationLandscapeRight: [webView stringByEvaluatingJavaScriptFromString:@"window.__defineGetter__('orientation',function(){return -90;});window.onorientationchange();"]; break; case UIDeviceOrientationPortraitUpsideDown: [webView stringByEvaluatingJavaScriptFromString:@"window.__defineGetter__('orientation',function(){return 180;});window.onorientationchange();"]; break; default: break; } }
Similar Threads
-
Sencha in UIWebView?
By bessfernandez in forum Sencha Touch 1.x: DiscussionReplies: 4Last Post: 29 Oct 2010, 12:58 AM -
Do nothing onOrientationchange.
By gabrielstuff in forum Sencha Touch 1.x: DiscussionReplies: 3Last Post: 7 Sep 2010, 4:04 PM -
changing scroll direction onOrientationChange
By cabennett85 in forum Sencha Touch 1.x: DiscussionReplies: 1Last Post: 3 Aug 2010, 1:17 PM -
[FIXED-286][3.x] GroupTabPanel's beforegroupchange event is fired/handled incorrectly
By tookoo in forum Ext 3.x: BugsReplies: 4Last Post: 9 Dec 2009, 7:46 AM



Reply With Quote