navigationVar的translucent属性导致的viewFrame问题

问题:

    在使用navigationController时,我们创建控件并添加到self.view中会发现空间的Frame时从(0,0)开始。而我们要让控件正常显示,就要在y坐标上加64。

原因:

    这个问题时由navigationBar的translucent属性造成的,当这个属性设置为YES时,self.view的Frame从(0,0)开始,而设置为NO时,则从(0,64)开始,也正是navigationBar的底部。

    从iOS7开始,这个属性默认为YES。

@property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent

再说一个navigationBar的背景颜色设置:

    在设置navigationBar背景颜色时,使用的是setBarTintColor:

[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
[navigationBarAppearance setBarTintColor:[UIColor whiteColor]];

    以上两种设置第一种是在navigationController中设置,第二种是全局设置,在AppDelegate.m中设置。

    以下这种方法是无效的:

[self.navigationController.navigationBar setBackgroundColor:[UIColor whiteColor]];

    如果使用这种方法,并且translucent设置为YES时,设置完背景颜色后就会发现背景颜色上有一层白雾。

    

    

猜你喜欢

转载自blog.csdn.net/u012380572/article/details/81012810
今日推荐