zoukankan      html  css  js  c++  java
  • ios状态栏的一些操作

    1. [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //显示  
    2. [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; //隐藏  

    让状态栏显示网络等待标志

    状态栏是可以通过UIApplication类提供的一些方法来修改的,比如完全去掉状态栏或者修改风格,不过这些改变只是在你的程序内部,当你退出你的程序又会复原。

    1. UIApplication *myApp = [UIapplication sharedApplication];  

    1.隐藏状态栏

    1. [myApp setStatusBarHidden:YES animated:YES];  
    复制代码

    记得隐藏状态栏后的你的“桌面”就增加320×20的大小,所以最好是在任何window或者view创建之前隐藏它。

    2.状态栏风格

    1. [myApp setStatusBarStyle: UIStatusbarStyleBlackOpaque];  
    1. typedef enum {  
    2.         UIStatusBarStyleDefault,  
    3.         UIStatusBarStyleBlackTranslucent,  
    4.         UIStatusBarStyleBlackOpaque  
    5.     } UIStatusBarStyle;  

    3.状态栏方向

    1. [myApp setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];  
    1. typedef enum {  
    2.      UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,  
    3.      //竖屏,垂直向上  
    4.      UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,  
    5.      //竖屏,垂直方向上下颠倒  
    6.      UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,  
    7.      //设备逆时针旋转到横屏模式  
    8.      UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft  
    9.      //设备顺时针旋转到横屏模式  
    10.    } UIInterfaceOrientation;  

    有时候,需要在状态栏上显示一些自定义信息,比如新浪微博的官方iOS客户端:告知用户信息处于发送队列、发送成功或者发送失败。

    如上图,通过在状态栏显示自定义信息,可以给用户友好又不影响软件使用的提示。

    为此,我们显得定义一个自定义状态栏类,包含一个显示信息的Label:

    [cpp] view plaincopy
     
    1. @interface CustomStatusBar : UIWindow  
    2. {  
    3.     UILabel *_messageLabel;  
    4. }  
    5.   
    6. - (void)showStatusMessage:(NSString *)message;  
    7. - (void)hide;  
    8.   
    9. @end  


    接着,设置大小和系统状态栏一致,背景为黑色:

    [cpp] view plaincopy
     
    1. self.frame = [UIApplication sharedApplication].statusBarFrame;  
    2. self.backgroundColor = [UIColor blackColor];  


    到这里,为了让自定义的状态栏可以让用户看到,还需要设置它的windowLevel。

    在iOS中,windowLevel属性决定了UIWindow的显示层次。默认的windowLevel为UIWindowLevelNormal,即0.0。

    系统定义了三个层次如下,具体可参考官方文档

    [cpp] view plaincopy
     
    1. const UIWindowLevel UIWindowLevelNormal;  
    2. const UIWindowLevel UIWindowLevelAlert;  
    3. const UIWindowLevel UIWindowLevelStatusBar;  
    4. typedef CGFloat UIWindowLevel;  


    为了能够覆盖系统默认的状态栏,我们把自定义的状态栏的windowLevel调高点:

    [cpp] view plaincopy
     
    1. self.windowLevel = UIWindowLevelStatusBar + 1.0f;  


    最后,为显示信息和隐藏添加一点无伤大雅的动画:

    [cpp] view plaincopy
     
    1. - (void)showStatusMessage:(NSString *)message  
    2. {  
    3.     self.hidden = NO;  
    4.     self.alpha = 1.0f;  
    5.     _messageLabel.text = @"";  
    6.       
    7.     CGSize totalSize = self.frame.size;  
    8.     self.frame = (CGRect){ self.frame.origin, 0, totalSize.height };  
    9.       
    10.     [UIView animateWithDuration:0.5f animations:^{  
    11.         self.frame = (CGRect){ self.frame.origin, totalSize };  
    12.     } completion:^(BOOL finished){  
    13.         _messageLabel.text = message;  
    14.     }];  
    15. }  
    16.   
    17. - (void)hide  
    18. {  
    19.     self.alpha = 1.0f;  
    20.       
    21.     [UIView animateWithDuration:0.5f animations:^{  
    22.         self.alpha = 0.0f;  
    23.     } completion:^(BOOL finished){  
    24.         _messageLabel.text = @"";  
    25.         self.hidden = YES;  
    26.     }];;  
    27. }  
     
  • 相关阅读:
    hdu5616 暴力枚举
    codeforce 35C fire again
    常用代码及经验总结(不断更新)
    codeforce AIM tech Round 4 div 2 B rectangles
    codeforce diversity
    codeforce 589B枚举
    codeforces 1A
    自学Java测试代码
    自学Jav测试代码三 Math类 & Date & GregorianCalendar类
    数学类与图形类
  • 原文地址:https://www.cnblogs.com/fuunnyy/p/4705967.html
Copyright © 2011-2022 走看看