Animate the gradient on the status bar
Effect
Description
1. Tips to display information on the status bar and overwrite status bar information
2. This design supports external message view customization, only need to implement the prescribed protocol method can
Source
Https://github.com/YouXianMing/StatusBarMessage
////StatusMessage.h//Statusbarview////Created by youxianming on 15/7/24.//Copyright (c) 2015 youxianming. All rights reserved.//#import<UIKit/UIKit.h>#import "StatusMessageProtocol.h"@interfaceStatusmessage:uiview/** * Display loaded View * * @param view implements STATUSMESSAGEPROTOCOL View * @param duration animation display time*/+ (void) Showwithview: (UIView <StatusMessageProtocol> *) View Duration: (nstimeinterval) duration;/** * Hide Loaded View * * @param duration hidden animation display time*/+ (void) Hidewithduration: (nstimeinterval) duration;////////////////////////////////////////////////////////////////////////////////////////////////////** * set display and hidden animation time (not set, default is 1s) * * @param duration animation time*/+ (void) Showandhideduration: (nstimeinterval) duration;/** * Display view, then hidden after a few seconds * * @param view implements Statusmessageprotocol View * @param seconds delay after a few seconds to hide*/+ (void) Showwithview: (uiview<statusmessageprotocol> *) View Hideafterseconds: (nstimeinterval) seconds;@end
////STATUSMESSAGE.M//Statusbarview////Created by youxianming on 15/7/24.//Copyright (c) 2015 youxianming. All rights reserved.//#import "StatusMessage.h"#defineStatus_message @ "StatusMessage"StaticUIWindow *_statuswindow =Nil;StaticNsmaptable *_weakdictionary =Nil;StaticNstimeinterval _animationduration =1. F;@implementationStatusMessage+ (void) Initialize {if(self = = [StatusMessageclass]) {_weakdictionary=[nsmaptable strongtoweakobjectsmaptable]; _statuswindow=[[UIWindow alloc] initwithframe:status_bar_frame]; _statuswindow.windowlevel= Uiwindowlevelstatusbar +1; _statuswindow.userinteractionenabled=NO; [_statuswindow makekeyandvisible]; }}+ (void) Showwithview: (UIView <StatusMessageProtocol> *) View Duration: (nstimeinterval) Duration {[_weakdictionary setobject:view forkey:status_message]; [_statuswindow Addsubview:view]; [View showwithduration:duration];}+ (void) Hidewithduration: (nstimeinterval) duration {UIView<StatusMessageProtocol> *tmpview =[_weakdictionary Objectforkey:status_message]; [Tmpview hidewithduration:duration];}+ (void) Showandhideduration: (nstimeinterval) duration {_animationduration=duration;}+ (void) Showwithview: (uiview<statusmessageprotocol> *) View Hideafterseconds: (nstimeinterval) seconds {[_weakdictionary setobject:view forkey:status_message]; [_statuswindow Addsubview:view]; [View Showwithduration:_animationduration]; Dispatch_after (Dispatch_time (dispatch_time_now, Seconds* nsec_per_sec), Dispatch_get_main_queue (), ^{UIView<StatusMessageProtocol> *tmpview =[_weakdictionary Objectforkey:status_message]; [Tmpview hidewithduration:_animationduration]; });}@end
////StatusMessageProtocol.h//Statusbarview////Created by youxianming on 15/7/24.//Copyright (c) 2015 youxianming. All rights reserved.//#import<Foundation/Foundation.h>/** * The frame value of the status bar*/#defineStatus_bar_frame [[UIApplication sharedapplication] statusbarframe]@protocolStatusmessageprotocol <NSObject>@required/** * Show Animation * * @param seconds Show duration*/- (void) Showwithduration: (nstimeinterval) seconds;/** * Hide the animation (remove yourself when you hide the animation) * * @param seconds hidden duration*/- (void) Hidewithduration: (nstimeinterval) seconds;@end
Animate the gradient on the status bar