【问题标题】:NativeControls and Device OrientationNativeControls 和设备方向
【发布时间】:2011-08-09 13:27:44
【问题描述】:

我在 PhoneGap iOS 应用中使用 NativeControls 插件和原生页脚栏。

当我旋转我的 iPhone 时,页脚栏也会旋转,但它只显示一个没有任何图标的黑条......当我移动到另一个页面时,整个界面完全崩溃,我需要重新启动应用程序。

有人知道怎么解决吗?也许 NativeControls 插件不兼容横向?

【问题讨论】:

    标签: cordova device-orientation


    【解决方案1】:

    从未真正实现对设备旋转的支持。 步骤如下:

    1) 添加方向监听器:

    document.addEventListener("orientationChanged",redrawTabBar,false);
    

    2) 添加方向改变时调用的函数:

    function redrawTabBar() {
        if (navigator.notification){
            PhoneGap.exec("NativeControls.redrawTabBar");
        }
    }
    

    3)在实际插件(.m)中添加方法:

    - (void)redrawTabBar:(NSArray*)arguments withDict:(NSDictionary*)options
    {
        tabBar.frame=CGRectMake(0, self.webView.frame.size.height, self.webView.frame.size.width, 50);
    }
    

    4) 确保orientationChanged 事件被webview 触发。 MainViewcontroller.m 内部

    - (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* jsString = 
        @"(function(){"
        "var e = document.createEvent('Events');"
        "e.initEvent('orientationChanged');"
        "document.dispatchEvent(e);"
        "})();";
        NSLog(@"Orientation Changed");
        [self.webView stringByEvaluatingJavaScriptFromString:jsString];
    }
    

    【讨论】:

    • 我也有同样的问题。但是,我似乎没有 MainViewcontroller.m 文件。你能澄清一下那篇文章吗??
    猜你喜欢
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    相关资源
    最近更新 更多