国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

i-OS開發:自定義狀態欄代碼詳解

2019-11-02 14:24:47
字體:
來源:轉載
供稿:網友

   公司的開發的項目要求在狀態欄上邊加入程序下載的進度條,之前寫的程序,由于是根據ipad的朝向來設置自定義的狀態欄的frame,以及子視圖的 frame和transform,出現一些不太容易解決的bug。這兩天正好項目不太緊,就好好學習一下這方面的知識,以下是我所總結的一點經驗:

  這里說明一下,Apple沒有開放的狀態欄的API,在ios 的官方文檔沒有提到修改Window Level的方式;

  先看一下Window Level的可用的值包括:

  1: typedef CGFloat UIWindowLevel;

  2: const UIWindowLevel UIWindowLevelNormal; // 0.0

  3: const UIWindowLevel UIWindowLevelAlert; // 2000.0

  4: const UIWindowLevel UIWindowLevelStatusBar; // 1000.0

  默認我們的UIView layer都是在UIWindowLevelNormal上,這也就是為什么系統彈出來的對話框在我們的視圖之上,因為它的Window Level級別更高。

  根據WindowLevel的原理我們也就知道,如果想在系統的狀態欄上,添加自定義的狀態欄,就需要比UIWindowLevelStatusBar的級別更高,接下來,用代碼說明一下:

  首先,先建一個Single View Application,名字自定義就可以了,

  然后,新建一個類命名為: StatusBarOverlay 繼承自UIWindow類,代碼:

  StatusBarOverlay.h文件

  1: #import

  2:

  3: @interface StatusBarOverlay : UIWindow{

  4: UIView *contentView;

  5: UILabel *textLabel;

  6: }

  7:

  8: @property (nonatomic, retain) UIView *contentView;

  9:

  10: @property (nonatomic, retain) UILabel *textLabel;

  11:

  12: @end

  StatusBarOverlay.m文件

  1: //

  2: // StatusBarOverlay.m

  3: // StatusBarDemo

  4: //

  5: // Created by jordy wang on 12-8-7.

  6: // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.

  7: //

  8:

  9: #import "StatusBarOverlay.h"

  10:

  11: #define STATUS_BAR_ORIENTATION [UIApplication sharedApplication].statusBarOrientation

  12: #define ROTATION_ANIMATION_DURATION [UIApplication sharedApplication].statusBarOrientationAnimationDuration

  13:

  14:

  15: @interface StatusBarOverlay()

  16:

  17: - (void)initializeToDefaultState;

  18: - (void)rotateStatusBarWithFrame:(NSValue *)frameValue;

  19: - (void)setSubViewHFrame;

  20: - (void)setSubViewVFrame;

  21: @end

  22:

  23:

  24: @implementation StatusBarOverlay

  25: @synthesize contentView;

  26: @synthesize textLabel;

  27:

  28: //重寫init方法

  29: - (id)init

  30: {

  31: self = [super initWithFrame:CGRectZero];

  32: if (self) {

  33: self.windowLevel = UIWindowLevelStatusBar + 1;

  34: self.frame = [UIApplication sharedApplication].statusBarFrame;

  35: [self setBackgroundColor:[UIColor orangeColor]];

  36: [self setHidden:NO];

  37:

  38: //內容視圖

  39: UIView *_contentView = [[UIView alloc] initWithFrame:self.bounds];

  40: self.contentView = _contentView;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德钦县| 唐河县| 波密县| 张家港市| 嫩江县| 昭苏县| 济南市| 正定县| 达拉特旗| 武冈市| 景泰县| 牙克石市| 伊通| 循化| 周口市| 南丰县| 秀山| 山东省| 渑池县| 临漳县| 竹山县| 乃东县| 柳林县| 冷水江市| 沈阳市| 潮安县| 界首市| 宝应县| 额尔古纳市| 洪湖市| 桦甸市| 江西省| 余姚市| 平陆县| 盖州市| 会同县| 宜兰市| 光山县| 乳山市| 眉山市| 涞水县|