2

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

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

有谁知道如何解决它?也许 NativeControls 插件与横向不兼容?

4

1 回答 1

0

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

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];
}
于 2012-03-31T14:15:22.977 回答