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

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

iOS瘋狂-詳解之自定義狀態欄代碼解析

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

   這里說明一下,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 = _

北京電影網[www.aikan.tv/special/beijingdianyingwang/]
contentView;

  41: [self.contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 额敏县| 温泉县| 阿瓦提县| 厦门市| 淮滨县| 房山区| 定兴县| 常德市| 遂川县| 长寿区| 天峻县| 凤山市| 多伦县| 楚雄市| 牟定县| 勃利县| 页游| 神木县| 资中县| 信丰县| 通州区| 团风县| 中超| 怀集县| 合水县| 铅山县| 南木林县| 建阳市| 通辽市| 延津县| 兰考县| 阳东县| 耒阳市| 庆安县| 资源县| 区。| 岳西县| 韶山市| 开原市| 波密县| 平山县|