iOS6與iOS7螢幕適配技巧

來源:互聯網
上載者:User

標籤:

一、沒有封裝任何 導航控制器 或者UITabBarController

1.控制器的view是UIScrollView/UITableView/UICollectionView時(控制器是UITableViewController的時候)

- (void)viewDidLoad

{

    [super viewDidLoad];

// #ifdef __IPHONE_7_0是判斷是否運行在Xcode5環境下,如果在Xcode5環境下才有下面的代碼

#ifdef __IPHONE_7_0

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {

        self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);

    }

#endif

}

 

2.控制器的view是普通的UIView,非UIScrollView

#ifdef __IPHONE_7_0

- (void)viewDidLayoutSubviews

{

    // iOS7 && 沒有封裝導航控制器

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0 &&self.navigationController == nil) {

        CGFloat top = [self.topLayoutGuide length];

        

        // 是否能滾動

        if ([self.view isKindOfClass:[UIScrollView class]]) {

            UIScrollView *scroll = (UIScrollView *)self.view;

            scroll.contentInset = UIEdgeInsetsMake(top, scroll.contentInset.left, scroll.contentInset.bottom, scroll.contentInset.right);

        } else {

            CGRect bounds = self.view.bounds;

            bounds.origin.y =  - top;

            self.view.bounds = bounds;

        }

    }

}

#endif

 

二、封裝有導航控制器的情況

1> 控制器的view不是UIScrollView

#ifdef __IPHONE_7_0

if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {

    self.edgesForExtendedLayout = UIRectEdgeNone;

}

#endif

 

2> 控制器的view是UIScrollView

不需要寫額外的代碼適配

 

三、其他情況(上述情況不用死機,只要掌握以下幾點規律)

1.想讓view的內容往下挪動

1> UIView設定bounds的y值

2> UIScrollView設定contentInset的top值

 

2.防止子控制器的view被導覽列或者tabbar遮住

self.edgesForExtendedLayout = UIRectEdgeNone;

 

四、多控制器嵌套處理

1.當多重控制器嵌套的時候,最合理的方案是:UITabBarController內部嵌套UINavigationController

2.當UITableViewController的直接父控制器是UINavigationController時,不需要編寫任何適配代碼

3.其他非UITableViewController需要加上適配代碼

#ifdef __IPHONE_7_0

if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {

    self.edgesForExtendedLayout = UIRectEdgeNone;

}

#endif

 

iOS6與iOS7螢幕適配技巧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.