橫屏設置下調整騰訊微博SDK的受權頁面

#問題api

iOS6系統以上,APP若是必須橫屏顯示的狀況下,使用騰信微博SDK的時候,受權頁面右邊會出現一個很難看的黑色邊。code

如圖所示: 在此輸入圖片描述圖片

緣由是這個SDK沒有考慮到橫屏的支持,或者說是隻支持豎屏——它確實定義了只支持豎屏,惋惜iOS6以上的系統已經再也不經過it

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientatio{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientatio);
}

#解決的辦法io

經過運行時找到受權的View Controller,改變一下View的frame以及它的子View———一個UIWebView。

- (void)onLogin {
    [wbapi loginWithDelegate:self andRootController:self];
    [self fixedLandscapeView];
}
- (void)fixedLandscapeView {
    UIViewController *ctrl = self.presentedViewController;
    NSAssert([ctrl isKindOfClass:[UINavigationController class]], @"找不到控制器,SDK可能發生變化了");
    if ([ctrl isKindOfClass:[UINavigationController class]]) {
        UINavigationController *navCtrl = (UINavigationController *)ctrl;
        NSArray *ctrls = [navCtrl viewControllers];
        if ([ctrls count] > 0) {
            ctrl = ctrls[0];
            CGRect frame = [[UIScreen mainScreen] bounds];
            CGFloat tmp = frame.size.height;
            frame.size.height = frame.size.width;
            frame.size.width = tmp;
            ctrl.view.frame = frame;
            for (UIView *view in ctrl.view.subviews) {
                view.frame = frame;
            }
        }
    }
}

修正以後的效果: 在此輸入圖片描述微博

在此輸入圖片描述

還要,UIWebView的內容自動根據View的frame適應了。class

相關文章
相關標籤/搜索