#問題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