1. #11
    Sencha User
    Join Date
    Dec 2010
    Posts
    2
    Vote Rating
    0
    wingfeng is on a distinguished road

      0  

    Default


    Quote Originally Posted by milo08 View Post
    Hi lieselbr,

    yes you have to do this in the ViewController from your UIWebView, in the didRotateFromInterfaceOrientation function.

    Code:
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
    {
            [yourWebview stringByEvaluatingJavaScriptFromString:@"var e = document.createEvent('Events'); e.initEvent('orientationchange', true, false); document.dispatchEvent(e); "];    
    }
    that works, but in my tests is very slow. I don`t know its my app, i will test it.

    greetz

    milo
    It didn't work in sencha 1.0.1a and iOS 4.2.1 UIWebView

  2. #12
    Sencha User
    Join Date
    Aug 2010
    Location
    https://github.com/RandyMcMillan
    Posts
    27
    Vote Rating
    0
    RandyMcMillan is on a distinguished road

      0  

    Default 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

  3. #13
    Sencha User
    Join Date
    Dec 2010
    Posts
    2
    Vote Rating
    0
    wingfeng is on a distinguished road

      0  

    Default


    Thanks it works!

  4. #14
    Sencha User
    Join Date
    Oct 2008
    Location
    Italy
    Posts
    14
    Vote Rating
    0
    rdp is on a distinguished road

      0  

    Default


    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

  5. #15
    Sencha User
    Join Date
    Jan 2011
    Posts
    26
    Vote Rating
    1
    danmux is on a distinguished road

      0  

    Default


    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

  6. #16
    Sencha User
    Join Date
    Aug 2011
    Location
    London
    Posts
    16
    Vote Rating
    1
    trkaky is on a distinguished road

      0  

    Default


    Thanks for the code partly solved my problem but Ext.Viewport.orientation always returns 'Portrait' even if its not.

    Any idea?

    Thanks

  7. #17
    Sencha User
    Join Date
    Aug 2011
    Location
    London
    Posts
    16
    Vote Rating
    1
    trkaky is on a distinguished road

      0  

    Default


    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

  1. Sencha in UIWebView?
    By bessfernandez in forum Sencha Touch 1.x: Discussion
    Replies: 4
    Last Post: 29 Oct 2010, 12:58 AM
  2. Do nothing onOrientationchange.
    By gabrielstuff in forum Sencha Touch 1.x: Discussion
    Replies: 3
    Last Post: 7 Sep 2010, 4:04 PM
  3. changing scroll direction onOrientationChange
    By cabennett85 in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 3 Aug 2010, 1:17 PM
  4. Replies: 4
    Last Post: 9 Dec 2009, 7:46 AM

Thread Participants: 9

Tags for this Thread