状态栏动画切换效果

时间:2022-01-23 22:35:40

状态栏动画切换效果

状态栏动画切换效果

 

效果

状态栏动画切换效果

 

源码

https://github.com/YouXianMing/iOS-Project-Examples 中的 StatusBarAnimation

//
// StatusBarValue.h
// StatusBarAnimation
//
// Created by YouXianMing on 16/7/18.
// Copyright © 2016年 YouXianMing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface StatusBarValue : NSObject

@property (nonatomic, weak) UIViewController
*controller;

/**
* Default value is UIStatusBarAnimationFade.
*/
@property (nonatomic) UIStatusBarAnimation animationType;

/**
* Default value is UIStatusBarStyleDefault.
*/
@property (nonatomic) UIStatusBarStyle style;

/**
* Default value is NO.
*/
@property (nonatomic) BOOL hidden;

/**
* SetNeedsStatusBarAppearanceUpdate
*
* @param animated Animated or not.
* @param duration Animation's duration.
*/
- (void)statusBarAppearanceUpdateAnimated:(BOOL)animated duration:(NSTimeInterval)duration;

#pragma mark - Constructor

+ (instancetype)statusBarValueWithController:(UIViewController *)controller;

@end
//
// StatusBarValue.m
// StatusBarAnimation
//
// Created by YouXianMing on 16/7/18.
// Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "StatusBarValue.h"

@implementation StatusBarValue

- (instancetype)init {

if (self = [super init]) {

self.animationType
= UIStatusBarAnimationFade;
self.style
= UIStatusBarStyleDefault;
self.hidden
= NO;
}

return self;
}

- (void)statusBarAppearanceUpdateAnimated:(BOOL)animated duration:(NSTimeInterval)duration {

if (self.controller) {

if (animated) {

[UIView animateWithDuration:duration
> 0 ? duration : 0.35f animations:^{

[self.controller setNeedsStatusBarAppearanceUpdate];
}];

}
else {

[self.controller setNeedsStatusBarAppearanceUpdate];
}
}
}

+ (instancetype)statusBarValueWithController:(UIViewController *)controller {

StatusBarValue
*value = [[[self class] alloc] init];
value.controller
= controller;

return value;
}

@end