iOS7 SDK各種坑——手Q團隊總結

來源:互聯網
上載者:User

標籤:

 http://s.p.qq.com/pub/show?p=82e0c8d9&id=4f6fdb7610fed&plg_auth=1&pt=4&puin=2195769561&idx=1&st=32014年04月14日

antonyzhao(趙峰) SNG即通產品部\平台開發組副組長

 

IViewController布局

wantsFullScreenLayout已經作廢了,取而代之是

1、edgesForExtendedLayout

這個屬性是UIExtendedEdge類型,用來制定視圖的哪條邊需要擴充。比如UIRectEdgeTop,它把視圖地區頂部擴充到statusBar(以前是navigationBar下面);UIRectEdgeBottom是把地區底部擴充到螢幕下方邊緣。預設值是UIRectEdgeAll。

2、extendedLayoutIncludesOpaqueBars

如果你使用了不透明的導覽列,設定edgesForExtendedLayout的時候也請將 extendedLayoutIncludesOpaqueBars的值設定為No(預設值是YES)。

3、automaticallyAdjustsScrollViewInsets

為YES時,它會找view裡的scrollView,並設定scrollView的contentInset為{64, 0, 0, 0}。如果你不想讓scrollView的內容自動調整,將這個屬性設為NO(預設值YES)。

目前QQ重載了wantsFullScreenLayout屬性方法:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000

- (void)QQSetWantsFullScreenLayout:(BOOL)wantsFullScreenLayout

{

    if (SYSTEM_VERSION >= 7.0) {

        if (wantsFullScreenLayout == NO) {

            self.automaticallyAdjustsScrollViewInsets = NO;

            self.extendedLayoutIncludesOpaqueBars = NO;

            self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;

        } else {

            self.automaticallyAdjustsScrollViewInsets = NO; // 建議手工設定

            self.extendedLayoutIncludesOpaqueBars = NO;

            self.edgesForExtendedLayout = UIRectEdgeAll;

        }

    }

 

    [self QQSetWantsFullScreenLayout:wantsFullScreenLayout];

}

#endif

QQViewController在初始化時,self.wantsFullScreenLayout=NO。也就是

            self.automaticallyAdjustsScrollViewInsets = NO;

            self.extendedLayoutIncludesOpaqueBars = NO;

            self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;

 

·    UITabBarController的視圖結構變了

 

 

iOS7以下,UITransitionView和UITabBar是不能重疊的。而iOS7兩個view是可以互相重疊。這影響我們自訂TabBar的實現機制(具體看QQTabBarController的實現方式)。

 

·    iOS7的UITableViewCell

1、iOS7下cell的backgroundColor為whiteColor,要手工設定為clearColor。

2、以前可以直接繼承UITableViewCell然後drawRect。但是現在不行了,現在的UITableViewCell包含了一個scrollView,你重繪了UITableViewCell將會被這個scrollView遮住而完全沒法顯示。而且不要試圖通過[cell.contentView viewWithTag]來擷取裡面的subview。

3、如果設定backgroundView和selectedBackgroundView,滑動刪除時會發現backgroundView會右移直到覆蓋刪除按鈕。目前解決辦法是在cell layoutSubviews方法重設backgroundView和selectedBackgroundView的frame:

- (void)layoutSubviews

{

    [super layoutSubviews];

 

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000

    if (SYSTEM_VERSION >= 7.0) {

        self.backgroundView.frame = self.bounds;

        self.selectedBackgroundView.frame = self.bounds;

    }

#endif

}

4、索引背景條backgroundColor預設為whiteColor,要把它改為clearColor:

[[UITableView appearance] setSectionIndexBackgroundColor:[UIColor clearColor]];

對應tapd bug:

http://tapd.oa.com/v3/10066451/bugtrace/bugs/view?bug_id=1010066451048986804&url_cache_key=74876e4d2f0fea09480c42284f702c98

 

·    iOS7基於viewController隱藏狀態條

通過ViewController重載方法返回枚舉值來控制狀態列的隱藏和樣式。

首先,需要在Info.plist設定檔中,增加鍵:UIViewControllerBasedStatusBarAppearance,並設定為YES;

然後,在UIViewController子類中實現以下兩個方法:

- (UIStatusBarStyle)preferredStatusBarStyle

{

    return UIStatusBarStyleLightContent;

}

- (BOOL)prefersStatusBarHidden

{

    return NO;

}

最後,在需要重新整理狀態列樣式的時候,調用[self setNeedsStatusBarAppearanceUpdate]方法即可重新整理。

 

目前QQ是把UIViewControllerBasedStatusBarAppearance設為NO,然後根據主題配置項統一設定statusBar的樣式

 

·    UINavigationBar和UINavigationBarItem

1、在iOS7下,如果設定的背景圖大於88像素,則它會自動展開到狀態列。(白色皮膚切圖有點bug,背景圖高度為89像素)

 

 

2、如果UINavigationBarItem是自訂CustomView,則效果如下

 

 

按鈕會在左邊(右邊)留下不少空白。目前解決方案是在leftBarButtonItem(rightBarButtonItem)左邊加一個width為-10、BarButtonSystemItem為UIBarButtonSystemItemFixedSpace的UIBarButtonItem。參考代碼在UINavigationItem+SwizzleMethod.m。

 

·    UISearchBar和UISearchDisplayController

1、測試在測試iOS7 SDK相容性時,發現導覽列和搜尋方塊之間有一條莫名其妙的線:

 

 

經debug分析,以前UISearchBar的子view有好幾個,包括背景圖view、輸入框view等。現在只有一個子view,而背景圖和輸入框等在這個子view裡。當table移動時,這個子view的frame也在不停變化,當table移動到最上面時,子view的frame.origin.y=0.5,而view. clipToBounds=YES,從而露出了viewController背景圖頂部的一條線……

2、給UISearchDisplayController設定delegate後,在UISearchDisplayController不用了的時候(比如release他之前),務必要setDelegate = nil。否則可能會出野指標(某已釋放的對象)被調用

self.searchDisplay.delegate = nil;

 

·    UILabel、UITextView、NSString的一些事

1、sizeWithFont、drawInRect等NSString的排版和繪製介面已經DEPRECATED,取而代之是sizeWithAttributes、drawInRect:withAttributes。

2、我們經常先用sizeWithFont對字串進行排版,然後設定UILabel的frame,在iOS7,可能出現下面問題

 

 

UILabel的內容顯示不完整,解決辦法是UILabel調用sizeToFit。

3、UITextView現在設定 text後contentSize返回大小和frame一樣,所以需要用sizeThatFits來替換。

 

·使用iOS7 SDK新特性導致iOS6 SDK編譯不過的解決辦法

例如UIStatusBarStyleLightContent是iOS7新的statusBarStyle,那寫代碼時,前面加上宏判斷:

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 70000

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
#else
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
#endif

iOS7 SDK各種坑——手Q團隊總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.