日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > php開(kāi)源 > 綜合技術(shù) > UIApplication、UIView、UIWindow、UIScreen、UIViewController、UINavigationController 介

UIApplication、UIView、UIWindow、UIScreen、UIViewController、UINavigationController 介

來(lái)源:程序員人生   發(fā)布時(shí)間:2015-04-25 09:44:55 閱讀次數(shù):6284次
轉(zhuǎn)載請(qǐng)聲明出處:http://blog.csdn.net/jinnchang/article/details/44954803

1、前言

我們先來(lái)看1下這幾個(gè)概念的類(lèi)繼承關(guān)系圖:

iOS 中,所有顯示在界面上的對(duì)象都是從 UIResponder 直接或間接繼承的。

2、利用程序(UIApplication)

1個(gè) UIApplication 對(duì)象就代表1個(gè)利用程序。1個(gè) iOS 程序啟動(dòng)后創(chuàng)建的第1個(gè)對(duì)象就是 UIApplication 對(duì)象(只有1個(gè)),而且是單例的。如有需要,可以通過(guò)以下代碼獲得該單例對(duì)象:

let app = UIApplication.sharedApplication()
利用 UIApplication 對(duì)象,可以進(jìn)行1些利用級(jí)別的操作。
(1)設(shè)置利用圖標(biāo)右上角的紅色提示數(shù)字

app.applicationIconBadgeNumber = 3
(2)設(shè)置聯(lián)網(wǎng)唆使器的可見(jiàn)性
app.networkActivityIndicatorVisible = true
(3)管理狀態(tài)欄
app.setStatusBarStyle(UIStatusBarStyle.Default, animated: true) app.setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade)
(4)openURL 方法
// 發(fā)信息 app.openURL(NSURL(string: "sms://10010")!) // 發(fā)郵件 app.openURL(NSURL(string: "mailto://jinnchang@126.com")!) // 打開(kāi)1個(gè)網(wǎng)頁(yè) app.openURL(NSURL(string: "http://blog.csdn.net/jinnchang")!) // 跳轉(zhuǎn)到 AppStore app.openURL(NSURL(string: "https://itunes.apple.com/cn/app/qq/id444934666?mt=8")!)
Github 上關(guān)于 UIApplication 的示例:UIApplicationSample

3、視圖(UIView)

UIView 的實(shí)例即視圖,負(fù)責(zé)在屏幕上定義1個(gè)矩形區(qū)域,同時(shí)處理該區(qū)域的繪制和觸屏事件。視圖可以嵌套,也能夠像圖層1樣進(jìn)行疊加。

// // ViewController.swift // UIViewControllerSample // // Created by jinnchang on 15/4/8. // Copyright (c) 2015年 Jinn Chang. All rights reserved. // import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // 添加1個(gè)黑色 view let view = UIView(frame: CGRectMake(40, 40, self.view.frame.size.width - 80, self.view.frame.size.height - 80)) view.backgroundColor = UIColor.blackColor() self.view.addSubview(view) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }

4、窗口(UIWindow)

UIWindow 管理和調(diào)和利用程序的顯示,雖然 UIWindow 繼承自 UIView,但通常不直接操作 UIWindow 對(duì)象中與視圖相干的屬性變量。
iOS 程序啟動(dòng)終了后,創(chuàng)建的第1個(gè)視圖控件就是 UIWindow(創(chuàng)建的第1個(gè)對(duì)象是 UIApplication),接著創(chuàng)建控制器的 view,最后將控制器的 view 添加到 window 上,因而控制器的 view 就顯示在屏幕上了。1般情況下,利用程序只有1個(gè) UIWindow 對(duì)象,即便有多個(gè),也只有1個(gè) UIWindow 可以接遭到用戶(hù)的觸屏事件。

(1)自定義1個(gè) myWindow

let myWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
(2)設(shè)置 myWindow 為主窗口并顯示出來(lái)(view 不能平空顯示,必須依賴(lài) window)
myWindow.makeKeyAndVisible()
UIWindow 和 UIView  之間的關(guān)系也能夠想象成這樣1個(gè)場(chǎng)景:首先會(huì)有1個(gè)空的畫(huà)框(UIWindow),我們?cè)诋?huà)框上放置1塊畫(huà)布(UIView),然后可以在這個(gè)畫(huà)布上進(jìn)行繪畫(huà)。畫(huà)布上可能會(huì)被畫(huà)上各種元素,例如 UILabel、UIButton 等,這些元素其實(shí)也是1個(gè)又1個(gè) UIView,它們會(huì)有1個(gè)層級(jí)關(guān)系管理,有點(diǎn)類(lèi)似于 Photoshop 中圖層的概念,層級(jí)高的元素會(huì)覆蓋住層級(jí)低的元素,從而致使層級(jí)低的元素被部份或完全遮擋。

5、屏幕(UIScreen)

通過(guò)這個(gè)類(lèi)我們可以獲得1些關(guān)于屏幕的信息,通經(jīng)常使用來(lái)獲得屏幕尺寸。

// 返回帶有狀態(tài)欄的 Rect let screenBounds = UIScreen.mainScreen().bounds // 返回不含狀態(tài)欄的 Rect let viewBounds = UIScreen.mainScreen().applicationFrame

6、視圖控制器(UIViewController)

視圖控制器管理 UIView 實(shí)例的生命周期及資源的加載與釋放、處理由于裝備旋轉(zhuǎn)致使的界面旋轉(zhuǎn)、和和用于構(gòu)建復(fù)雜用戶(hù)界面的高級(jí)導(dǎo)航對(duì)象進(jìn)行交互。

下圖展現(xiàn)了 UIView、UIWindow、UIScreen、UIViewController 之間的層級(jí)關(guān)系:


想要完全了解 UIViewController 用法可以參考 Github 上關(guān)于 UIViewController 的示例:UIViewControllerSample

7、導(dǎo)航控制器(UINavigationController)

在介紹 UINavigationController 之前先介紹另外一個(gè)概念:容器(Container)。1個(gè) app 可能有很多的 UIViewController 組成,這時(shí)候需要1個(gè)容器來(lái)對(duì)這些 UIViewController 進(jìn)行管理。大部份的容器也是1個(gè) UIViewController,如 UINavigationController、UITabBarController,也有少數(shù)不是 UIViewController,比如 UIPopoverController 等。
UINavigationController 繼承自 UIViewController,通常我們新建的工程是直接將視圖控制器添加到 window 上的,如果添加了 navigation 以后就多了1層。

// // AppDelegate.swift // UINavigationControllerSample // // Created by jinnchang on 15/4/8. // Copyright (c) 2015年 Jinn Chang. All rights reserved. // import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. // 初始化 window window = UIWindow(frame: UIScreen.mainScreen().bounds) window?.backgroundColor = UIColor.grayColor() // 初始化 navigationController let viewController = ViewController(nibName: nil, bundle: nil) let navigationController = UINavigationController(rootViewController: viewController) // 設(shè)置 window 的根控制器為 navigationController window?.rootViewController = navigationController // 設(shè)置 window 為主窗口并顯示出來(lái) window?.makeKeyAndVisible() return true } func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } }
以下是 UINavigationController 的結(jié)構(gòu)圖:

通過(guò) UINavigationController 進(jìn)行視圖切換的兩種經(jīng)常使用方式:

(1)presentViewController

// 向上彈出視圖 let firstViewController = FirstViewController(nibName: nil, bundle: nil) self.navigationController?.presentViewController(firstViewController, animated: true, completion: nil)
// 退出視圖 self.dismissViewControllerAnimated(true, completion: nil)
(2)pushViewController
// 向左推出視圖 let secondViewController = SecondViewController(nibName: nil, bundle: nil) self.navigationController?.pushViewController(secondViewController, animated: true);
// 退出視圖 self.navigationController?.popToRootViewControllerAnimated(true)
想要完全了解 UINavigationController 用法可以參考 Github 上關(guān)于 UINavigationController 的示例:UINavigationControllerSample

8、結(jié)語(yǔ)

文章最后更新時(shí)間:2015年4月9日09:17:44。參考資料以下:

About View Controllers

http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html

http://www.cnblogs.com/wendingding/p/3766347.html

生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線(xiàn)----------------------------
分享到:
------分隔線(xiàn)----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 一级黄色在线看 | 久草成人网 | 免费爱爱视频 | 精品国产乱码久久久久久丨区2区 | 欧美国产日韩视频 | 中文字幕第九页 | 亚洲国产精品一区二区三区 | 玖玖在线播放 | 久久久久国产一区二区三区四区 | 一区二区视频在线观看 | 亚洲一区二区综合 | 精品久久久免费 | av2014天堂网| 免费a级| 国产精品久久久久久久久久东京 | 日韩电影在线 | 毛片无码国产 | 美女视频黄网站 | 国产综合一区二区 | 欧美日韩中文字幕在线视频 | 岛国大片在线观看 | 国产精品久久久久久久久久久久久 | 成人高清av | 最近中文免费字幕 | 91精品久久久久久久久青青 | 国产男女免费完整视频 | 亚洲一区二区黄 | 国内精品久久久久久 | 岛国免费av | 成人永久免费视频 | 美女福利视频网站 | 成人综合av| 成人一区二区三区 | 成人高清在线视频 | 综合黄色 | 久久精品视频一区 | 黄色片免费在线观看 | 久久激情网站 | 亚洲精品一区国产精品 | 91精品国产91久久久久 | 精品成人在线视频 |