ios瘋狂詳解之自定義狀態(tài)欄代碼解析__第1頁(yè)
ios瘋狂詳解之自定義狀態(tài)欄代碼解析__第2頁(yè)
ios瘋狂詳解之自定義狀態(tài)欄代碼解析__第3頁(yè)
ios瘋狂詳解之自定義狀態(tài)欄代碼解析__第4頁(yè)
ios瘋狂詳解之自定義狀態(tài)欄代碼解析__第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、ios瘋狂詳解之自定義狀態(tài)欄代碼解析_ 這里說明一下,apple沒有開放的狀態(tài)欄的api,在ios 的官方文檔沒有提到修改window level的方式; 先看一下window level的可用的值包括: 1: typedef cgfloat uiwindowlevel; 2: const uiwindowlevel uiwindowlevelnormal; / 0.0 3: const uiwindowlevel uiwindowlevelalert; / 2021.0 4: const uiwindowlevel uiwindowlevelstatusbar; / 1000.0 默認(rèn)我們的

2、uiview layer都是在uiwindowlevelnormal上,這也就是為什么系統(tǒng)彈出來的對(duì)話框在我們的視圖之上,由于它的window level級(jí)別更高。 依據(jù)windowlevel的原理我們也就知道,假如想在系統(tǒng)的狀態(tài)欄上,添加自定義的狀態(tài)欄,就需要比uiwindowlevelstatusbar的級(jí)別更高,接下來,用代碼說明一下: 首先,先建一個(gè)single view application,名字自定義就可以了, 然后,新建一個(gè)類命名為: statusbaroverlay 繼承自u(píng)iwindow類,代碼: statusbaroverlay.h文件 1: #import 2: 3:

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 b

4、y jordy wang on 12-8-7. 6: / copyright (c) 2021年 _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.statusbaror

5、ientationanimationduration 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 con

6、tentview; 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: s

7、elf sethidden:no; 37: 38: /內(nèi)容視圖 39: uiview *_contentview = uiview alloc initwithframe:self.bounds; 40: self.contentview = _contentview; 41: self.contentview setautoresizingmask:uiviewautoresizingflexiblewidth; 42: self.contentview setbackgroundcolor:uicolor cyancolor; 43: self addsubview:self.conten

8、tview; 44: _contentview release; 45: 46: 47: /添加textlabel 48: uilabel *_textlabel = uilabel alloc initwithframe:cgrectmake(30, 0, cgrectgetwidth(self.frame)-60, cgrectgetheight(self.frame); 49: self.textlabel = _textlabel; 50: self.textlabel setbackgroundcolor:uicolor bluecolor; 51: self.textlabel s

9、etfont:uifont systemfontofsize:12; 52: self.textlabel settextalignment:uitextalignmentcenter; 53: self.textlabel settextcolor:uicolor blackcolor; 54: self.textlabel settext:自定義的狀態(tài)欄 author by jordy; 55: self.contentview addsubview:self.textlabel; 56: _textlabel release; 57: 58: /注冊(cè)監(jiān)聽-當(dāng)屏幕將要轉(zhuǎn)動(dòng)時(shí),所動(dòng)身的大事(

10、用于操作本視圖轉(zhuǎn)變其frame) 59: nsnotificationcenter defaultcenter addobserver:self selector:selector(willrotatescreenevent:) name:uiapplicationwillchangestatusbarframenotification object:nil; 60: /初始化 61: self initializetodefaultstate; 62: 63: 64: return self; 65: 66: 67: 68: 69: 70: /初始化為默認(rèn)狀態(tài) 71: - (void)ini

11、tializetodefaultstate 72: 73: /獵取當(dāng)前的狀態(tài)欄位置 74: cgrect statusbarframe = uiapplication sharedapplication.statusbarframe; 75: /設(shè)置當(dāng)前視圖的旋轉(zhuǎn), 依據(jù)當(dāng)前設(shè)備的朝向 76: self rotatestatusbarwithframe:nsvalue valuewithcgrect:statusbarframe; 77: 78: 79: 80: 81: 82: 83: /旋轉(zhuǎn)屏幕 84: - (void)rotatestatusbarwithframe:(nsvalue *)

12、framevalue 85: 86: cgrect frame = framevalue cgrectvalue; 87: uiinterfaceorientation orientation = status_bar_orientation; 88: 89: if (orientation = uideviceorientationportrait) 90: self.transform = cgaffinetransformidentity; /屏幕不旋轉(zhuǎn) 91: self setsubviewvframe; 92: else if (orientation = uideviceorien

13、tationportraitupsidedown) 93: self.transform = cgaffinetransformmakerotation(m_pi); /屏幕旋轉(zhuǎn)180度 94: self setsubviewvframe; 95: else if (orientation = uideviceorientationlandscaperight) 96: self.transform = cgaffinetransformmakerotation(m_pi * (-90.0f) / 180.0f); /屏幕旋轉(zhuǎn)-90度 97: self setsubviewhframe; 98

14、: else if (orientation = uideviceorientationlandscapeleft) 99: self.transform = cgaffinetransformmakerotation(m_pi * 90.0f / 180.0f); /屏幕旋轉(zhuǎn)90度 100: self setsubviewhframe; 101: 102: 103: self.frame = frame; 104: self.contentview setframe:self.bounds; 105: 106: 107: /設(shè)置橫屏的子視圖的frame 108: - (void)setsub

15、viewhframe 109: 110: self.textlabel.frame = cgrectmake(30, 0, 1024-60, 20); 111: 112: /設(shè)置豎屏的子視圖的frame 113: - (void)setsubviewvframe 114: 115: self.textlabel.frame = cgrectmake(30, 0, 748-60, 20); 116: 117: 118: #pragma mark - 119: #pragma mark 響應(yīng)屏幕即將旋轉(zhuǎn)時(shí)的大事響應(yīng) 120: - (void)willrotatescreenevent:(nsnot

16、ification *)notification 121: 122: nsvalue *framevalue = notification.userinfo valueforkey:uiapplicationstatusbarframeuserinfokey; 123: self rotatestatusbaranimatedwithframe:framevalue; 124: 125: 126: - (void)rotatestatusbaranimatedwithframe:(nsvalue *)framevalue 127: uiview animatewithduration:rota

17、tion_animation_duration animations: 128: self.alpha = 0; 129: completion:(bool finished) 130: self rotatestatusbarwithframe:framevalue; 131: uiview animatewithduration:rotation_animation_duration animations: 132: self.alpha = 1; 133: ; 134: ; 135: 136: 137: - (void)dealloc 138: 139: nsnotificationce

18、nter defaultcenter removeobserver:self; 140: textlabel release; 141: textlabel = nil; 142: 143: contentview release; 144: contentview = nil; 145: 146: super dealloc; 147: 148: 149: end 由于代碼比較簡(jiǎn)潔,并且我在上述代碼里有相應(yīng)的說明,這里需要說明一點(diǎn)的是,默認(rèn)我們繼承自u(píng)iwindow的statusbaroverlay類是hidden狀態(tài),需要在初始化的時(shí)候設(shè)置它的hidden屬性為no, 在屏幕旋轉(zhuǎn)過程中,自定義的狀態(tài)欄與uiviewcon

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論