cordova-plugin-statusbar 插件 切換 view 後頁面上移 bug 原

2017年01月12日 左右下載插件的 bug。

例如使用掃二維碼插件、選擇相片會切換 view。之後 cordova 的 webview 就和屏幕最上邊對齊了。

然後就一臉西八。因爲頁面整個向上飄了 20 px。

此時心裏一萬隻草泥馬,因爲我根本不會 iOS 開發啊!!!然後硬着頭皮調試,果然功夫不負有心人,努力是不會騙人的,讓老子發現了,這裏看着不爽了。然後開啓了複製粘貼buff。成功了。我含着淚寫下了這篇博客以此紀念我花了1.4萬培訓的iOS餵了狗。

 

Plugins 下面的 CDVStatusBar.m 文件。

 

  官方當時的代碼:

-(void)resizeWebView
{
    BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0"));

    if (isIOS7) {
        CGRect bounds = [self.viewController.view.window bounds];
        bounds = [self invertFrameIfNeeded:bounds];

        if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
            self.viewController.view.frame = bounds;
        } else if (self.viewController.presentedViewController != nil) {
            // https://issues.apache.org/jira/browse/CB-11018
            BOOL isIOS8 = (IsAtLeastiOSVersion(@"8.0"));
            BOOL isIOS9 = (IsAtLeastiOSVersion(@"9.0"));
            if (isIOS8 && !isIOS9) {
                // iOS 8
                bounds = CGRectMake(0, 0, bounds.size.width, bounds.size.height);
            } else {
                // iOS7, iOS9+
                if ([self.viewController.presentedViewController.presentationController isKindOfClass:[UIPopoverPresentationController class]] || UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
                    bounds = CGRectMake(0, 0, bounds.size.width, bounds.size.height);
                } else {
                    bounds = CGRectMake(0, 0, bounds.size.height, bounds.size.width);
                }
            }
        }
        self.webView.frame = bounds;

        CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
        statusBarFrame = [self invertFrameIfNeeded:statusBarFrame];
        CGRect frame = self.webView.frame;
        CGFloat height = statusBarFrame.size.height;

        if (!self.statusBarOverlaysWebView) {
            // CB-10158 If a full screen video is playing the status bar height will be 0, set it to 20
            frame.origin.y = height > 0 ? height: 20;
        } else {
            // Even if overlay is used, we want to handle in-call/recording/hotspot larger status bar
            frame.origin.y = height >= 20 ? height - 20 : 0;
        }
        frame.size.height -= frame.origin.y;
        self.webView.frame = frame;
    } else {
        CGRect bounds = [[UIScreen mainScreen] applicationFrame];
        self.viewController.view.frame = bounds;
    }
}

錯了,反正有問題,我是看不懂。

 

回滾之前官方的代碼:

-(void)resizeWebView
{
    BOOL isIOS7 = (IsAtLeastiOSVersion(@"7.0"));

    if (isIOS7) {
        CGRect bounds = [[UIScreen mainScreen] bounds];
        bounds = [self invertFrameIfNeeded:bounds];
        
        if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
            self.viewController.view.frame = bounds;
        } else if (self.viewController.presentedViewController != nil) {
            // https://issues.apache.org/jira/browse/CB-11018
            BOOL isIOS8 = (IsAtLeastiOSVersion(@"8.0"));
            BOOL isIOS9 = (IsAtLeastiOSVersion(@"9.0"));
            if (isIOS8 && !isIOS9) {
                // iOS 8
                bounds = CGRectMake(0, 0, bounds.size.width, bounds.size.height);
            } else {
                // iOS7, iOS9+
                bounds = CGRectMake(0, 0, bounds.size.height, bounds.size.width);
            }
        }
        self.webView.frame = bounds;
        
        if (!self.statusBarOverlaysWebView) {
            CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
            statusBarFrame = [self invertFrameIfNeeded:statusBarFrame];
            CGRect frame = self.webView.frame;
            frame.origin.y = statusBarFrame.size.height;
            frame.size.height -= statusBarFrame.size.height;
            self.webView.frame = frame;
        }
    } else {
        CGRect bounds = [[UIScreen mainScreen] applicationFrame];
        self.viewController.view.frame = bounds;
    }
}

反正這樣就好了。你也可以試試。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章