自定义状态栏UIStatusBar

类似微博发送信息时,在状态栏提示消息的效果。主要实现思想是继承UIWindow,然后设置windowlevel的级别高于UIStatusBar。最后把自定义的statusbar放置在原来的statusbar指定的位置上。


#import <UIKit/UIKit.h>

@interface SendVoiceTipsView : UIWindow
{
    UILabel* messageLabel;
}

-(void)startTips:(NSString*)startMsg;
-(void)stopTips:(NSString*)stopMsg;
@end



#import "SendVoiceTipsView.h"
#import <QuartzCore/QuartzCore.h>
@implementation SendVoiceTipsView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.windowLevel  = UIWindowLevelAlert + 1;
        self.backgroundColor = [UIColor clearColor];
        messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(320*2/3, 0, 320/3, frame.size.height)];
        messageLabel.backgroundColor = [UIColor blackColor];
        messageLabel.textColor = [UIColor grayColor];
        messageLabel.textAlignment = UITextAlignmentRight;
        messageLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:messageLabel];
    }
    return self;
}
//显示在状态栏上提示发送说说中
-(void)startTips:(NSString *)startMsg{
    messageLabel.text = startMsg;
    self.windowLevel  = UIWindowLevelAlert + 1;
    [self makeKeyAndVisible];
}
//隐藏状态栏上的提示
-(void)stopTips:(NSString *)stopMsg{
    messageLabel.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, 1, 0, 0);
    [UIView animateWithDuration:0.7 animations:^{
        messageLabel.layer.transform = CATransform3DIdentity;
        messageLabel.text = stopMsg;
    }completion:^(BOOL finished){
        double delayInSeconds = 1;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [UIView animateWithDuration:0.5 animations:^{
                messageLabel.layer.transform = CATransform3DMakeRotation(M_PI * 0.5, -1, 0, 0);
            }completion:^(BOOL finished){
                self.windowLevel  = UIWindowLevelStatusBar - 1;
                [[[UIApplication sharedApplication].delegate window] makeKeyAndVisible];
            }];
        });
    }];

}

@end

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值