截个图
在图中可以看出当:
1.translucent设置为YES时,视图的frame大小为(0,0,414,736) 即视图顶部从'屏幕顶部'开始计算
,导航栏背景为半透明通过导航栏可以看到下面的视图,但是是半透明
;
2.translucent设置为NO时,视图frame大小为(0,64,414,672)即视图顶部从'导航栏底部'开始计算
,导航栏背景为不透明
;
3.这个属性在scrollView做子视图时也是有效的;
4.这个属性可以与NavigationBar.hidden属性合用产生奇妙的化学反应;
官方的解释是:
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) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
大意是:从iOS7开始默认为YES;
将它设置成NO时背景不透明;
如果设置成YES ,放了一副不透明的图,自动会把这个图弄成半透明;
如果设置成NO,放了一副半透明的图,
如果barstyle是UIBarStyleBlack,效果是将半透明的图自动加上黑色背景
如果barstyle是UIBarStyleDefault,效果是将半透明的图自动加上白色背景
如果设置了barTintColor,效果是将半透明的图自动加上barTintColor的背景