利用UIWindow實現密碼保護功能,uiwindow密碼保護

來源:互聯網
上載者:User

利用UIWindow實現密碼保護功能,uiwindow密碼保護
需求描述
使用者從任一介面按Home鍵退出,再從後台切換回來時,顯示一個密碼輸入介面,只有使用者輸入正確的密碼,才能進入退出前的介面。
需求分析
由於密碼輸入介面可能從任何應用介面彈出,且需要蓋在所有介面的最上層,所以需喲用UIView來實現
基礎知識
UIWindow的主要作用:
1.作為UIView的最頂層容器,包含應用顯示需要的所有的UIView

2. 傳遞觸摸訊息和鍵盤事件給UIView

具體實現

+ (PasswordInputWindow *)sharedInstance{    static id sharedInstance = nil;    static dispatch_once_t onceToken;        dispatch_once(&onceToken, ^{                sharedInstance = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    });        return sharedInstance;}- (id)initWithFrame:(CGRect)frame{        self = [super initWithFrame:frame];        if (self) {//setup UI}- (void)show{    [self makeKeyWindow];    self.hidden = NO;}

在APPDelegate的下面回調方法中使用該Window

- (void)applicationWillEnterForeground:(UIApplication *)application {       [[PasswordInputWindow sharedInstance] show];}

額外的獎勵
通過建立UIWindow,我們可以很容易的實現將某些特定介面置於最上層的效果,但是這種特性最好只用於無法確定該視圖應該在哪個控制器上面,若明確視圖應該出現在哪個控制器上面,則一般選擇在該控制器上建立新的視圖來實現該功能。此外,在一個項目中不應該過多的建立這種UIWindow單例對象,眾所周知,單例會一直保持在記憶體中,得不到釋放!


搬磚工看這裡: http://download.csdn.net/detail/luozhonglan/8608207


******************************************************************************************************************************************************************************************************

posted by  羅大佑子

2015-4-18



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.