今天花了一下午的時(shí)間解決iOS的適配問題,本來使用了autolayout好好的,一個(gè)新同事拿到ios6.1上去一測,導(dǎo)航條和view中間空了一大截。
著了好多辦法,最后發(fā)現(xiàn)蘋果公司對iOS7.0專門設(shè)置了一個(gè)屬性:
/*
 New behavior on iOS 7.
 Default is YES.
 You may force an opaque background by setting the property to NO.
 If the navigation bar has a custom background image, the default is inferred 
 from the alpha values of the image—YES if it has any pixel with alpha < 1.0
 If you send setTranslucent:YES to a bar with an opaque custom background image
 it will apply a system opacity less than 1.0 to the image.
 If you send setTranslucent:NO to a bar with a translucent custom background image
 it will provide an opaque background for the image using the bar's barTintColor if defined, or black
 for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.
 
*/
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0); // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent

好吧,問題就在這里。在代碼中做一下系統(tǒng)版本判斷,然后設(shè)置這個(gè)屬性為NO。

一切就好了,哎,浪費(fèi)時(shí)間啊!如果不改它,autolayout就會(huì)和你做對的。各位珍重.
//繼承UINavigationController,加入一個(gè)實(shí)現(xiàn)
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    //適配ios7
    if( ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0)){
        self.navigationBar.translucent = NO;
    }
}