NativeControls 和设备方向

发布于 2024-11-28 19:24:11 字数 188 浏览 0 评论 0原文

我在我的 PhoneGap iOS 应用程序中使用 NativeControls 插件和本机页脚栏。

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

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

I'm using the NativeControls plugin and a native footerbar in my PhoneGap iOS app.

When I rotate my iPhone, the footerbar also rotates but it only shows a black bar without any icon... And when I move to another page, the whole interface is completely broken and I need to restart the app.

Does anyone know how to solve it? Maybe the NativeControls plugin is not compatible with landscape orientation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-12-05 19:24:11

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

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 事件由网页视图。 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];
}

Support for device rotation was never really implemented.
Here are the steps:

1) add the orientation listener:

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

2) add the function called when there is an orientation change:

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

3) add the method in the actual plugin (.m):

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

4) make sure the orientationChanged event is fired by the webview. Inside 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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文