動(dòng)態(tài)改變狀態(tài)欄

1. 9.0之前,改變狀態(tài)欄方式?

.plist 文件 設(shè)置?View controller-based status bar appearance = no; 不可以繼承全局狀態(tài)欄風(fēng)格,并重寫。

application.statusBarStyle = UIStatusBarStyleLightContent;?

// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system.

@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]") __TVOS_PROHIBITED;

2.9.0以后,可以通過(guò)?preferredStatusBarStyle 方式修改。

一 :首先設(shè)置.plist ?View controller-based status bar appearance = YES;

二:設(shè)計(jì)兩組改變方式:

1.(多個(gè))涉及是UINavigationController導(dǎo)航,動(dòng)態(tài)設(shè)置切換ViewController不同

2.(單個(gè))僅設(shè)計(jì)到某個(gè)ViewController變換

3.上述兩種情況又分切換類型:push,presentmodel等調(diào)用次序不同。

三:調(diào)用??[self setNeedsStatusBarAppearanceUpdate];

如果根導(dǎo)航是UINavigationController 不用在主動(dòng)調(diào)用,默認(rèn)調(diào)用該方法。



多個(gè):

// Override to return a child view controller or nil. If non-nil, that view controller's status bar appearance attributes will be used. If nil, self is used. Whenever the return values from these methods change, -setNeedsUpdatedStatusBarAttributes should be called.

#if UIKIT_DEFINE_AS_PROPERTIES

@property(nonatomic,readonly,nullable)UIViewController*childViewControllerForStatusBarStyleNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;

@property(nonatomic,readonly,nullable)UIViewController*childViewControllerForStatusBarHiddenNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;

#else

- (nullableUIViewController *)childViewControllerForStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;

- (nullableUIViewController *)childViewControllerForStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;

#endif

1.雖然View controller-based status bar appearance = YES;但是全局狀態(tài)欄樣式由RootViewController樣式?jīng)Q定。

2.重寫或分類重寫上面方法

- (nullableUIViewController *)childViewControllerForStatusBarStyle

- (nullableUIViewController *)childViewControllerForStatusBarHidden?


業(yè)務(wù)決定某個(gè)控制器狀態(tài)欄重寫一個(gè)或兩個(gè)方式:

- (UIStatusBarStyle)preferredStatusBarStyle

- (BOOL)prefersStatusBarHidden?


單個(gè)情況:

/* The preferredContentSize is used for any container laying out a child view controller.

?*/

@property(nonatomic)CGSizepreferredContentSizeNS_AVAILABLE_IOS(7_0);

// These methods control the attributes of the status bar when this view controller is shown. They can be overridden in view controller subclasses to return the desired status bar attributes.

#if UIKIT_DEFINE_AS_PROPERTIES

@property(nonatomic, readonly) UIStatusBarStyle preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; // Defaults to UIStatusBarStyleDefault


@property(nonatomic,readonly)BOOLprefersStatusBarHiddenNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;// Defaults to NO


// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.



@property(nonatomic,readonly)UIStatusBarAnimationpreferredStatusBarUpdateAnimationNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;// Defaults to UIStatusBarAnimationFade


#else



- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;// Defaults to UIStatusBarStyleDefault


- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;// Defaults to NO


// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.


- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;// Defaults to UIStatusBarAnimationFade

#endif

// This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.

- (void)setNeedsStatusBarAppearanceUpdateNS_AVAILABLE_IOS(7_0)__TVOS_PROHIBITED;

1.主動(dòng)觸發(fā)

[self setNeedsStatusBarAppearanceUpdate];

2.業(yè)務(wù)決定某個(gè)控制器狀態(tài)欄重寫一個(gè)或兩個(gè)方式:

- (UIStatusBarStyle)preferredStatusBarStyle

- (BOOL)prefersStatusBarHidden?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容