IOS7 適配以及向下兼容問題

1.全部的UIViewController加以下方法。

    - (void) viewDidLayoutSubviews {
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
            CGRect viewBounds = self.view.bounds;
            CGFloat topBarOffset = self.topLayoutGuide.length;
            viewBounds.origin.y = topBarOffset * -1;
            self.view.bounds = viewBounds;
            [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        }
    }
在項目的plist文件里加View controller-based status bar appearance,值爲no
 
 
2.scrollerView報錯,找不到setAutomaticallyAdjustsScrollViewInsets:方法,解決方法
 
重寫方法setAutomaticallyAdjustsScrollViewInsets:

- (void)setAutomaticallyAdjustsScrollViewInsets:(BOOL)automaticallyAdjustsScrollViewInsetsios

{app

    if(IS_IOS7){ide

        [super setAutomaticallyAdjustsScrollViewInsets:automaticallyAdjustsScrollViewInsets];ui

    }spa

}.net

而後viewDidLoad裏面加上:
if([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]){
      self.automaticallyAdjustsScrollViewInsets = NO;
}
 
3.再作ios7兼容的時候最好讓全部的UIViewController繼承一個本身定義的UIViewController,而後好統一管理。
 
4.UITableView cell的分割線不能靠左的解決方法
添加一句:
[UITableViewappearance].separatorInset=UIEdgeInsetsZero;
 
5.適配IOS7時使用edgesForExtendedLayout遇到的問題
代碼是navigationBar+tabBar組成的
在viewDidLoad里加了以下代碼,
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
      self.edgesForExtendedLayout = UIRectEdgeNone;
      self.extendedLayoutIncludesOpaqueBars = NO;  
      self.modalPresentationCapturesStatusBarAppearance = NO; 

      self.navigationController.navigationBar.barTintColor =[UIColor grayColor];
      self.tabBarController.tabBar.barTintColor =[UIColor grayColor];
}

加了以後UI顯示正常了,即沒有上移20的高度。
問題是,當運行程序,自動進入到tabBar對應的第一個頁面時,navigationBar和tabBar會出現黑色的背景,一小會會消失,才變成本身設置的背景色。
若是註釋掉上面代碼,進入程序時不會出現黑色背景,可是裏面的UI會上移20的高度...
解決方法:
self.navigationController.navigationBar.translucent = NO;         self.tabBarController.tabBar.translucent = NO;
copy from  http://blog.csdn.net/yongyinmg/article/details/23861853
相關文章
相關標籤/搜索