1. 程式人生 > >ios-day11-01(UIWindow的常用方法。makeKeyWindow、makeKeyAndVisible、獲取當前應用的主視窗和所有視窗)

ios-day11-01(UIWindow的常用方法。makeKeyWindow、makeKeyAndVisible、獲取當前應用的主視窗和所有視窗)

//
//  JLAppDelegate.h
//  01-UIWindow
//
//  Created by XinYou on 15-3-11.
//  Copyright (c) 2015ĺš´ vxinyou. All rights reserved.
//

#import 

@interface JLAppDelegate : UIResponder 

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UIWindow *window2;

@end
//
//  JLAppDelegate.m
//  01-UIWindow
//
//  Created by XinYou on 15-3-11.
//  Copyright (c) 2015年 vxinyou. All rights reserved.
//

#import "JLAppDelegate.h"

@implementation JLAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // 第1個window
    
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;
    self.window.backgroundColor = [UIColor redColor];
    
    // 讓window成為keyWindow(主視窗),預設不可見
//    [self.window makeKeyWindow];
    
    // 讓window成為keyWindow(主視窗),並且可見
    [self.window makeKeyAndVisible];
    
    // 給第1個window新增一個輸入框
    UITextField *tf = [[UITextField alloc] init];
    tf.frame = CGRectMake(10, 10, 100, 30);
    tf.borderStyle = UITextBorderStyleRoundedRect;
    [self.window addSubview:tf];
    
    // 列印當前應用的主視窗,此時應用的主視窗是window
    NSLog(@"%p", [UIApplication sharedApplication].keyWindow);
    
    // 第2個window
    self.window2 = [[UIWindow alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    self.window2.backgroundColor = [UIColor blueColor];
    
    // 讓window2成為keyWindow(主視窗),並且可見。此時window將不再是主視窗,但是仍然能顯示
    [self.window2 makeKeyAndVisible];
    
    // 給第2個window新增一個輸入框
    UITextField *tf2 = [[UITextField alloc] init];
    tf2.frame = CGRectMake(50, 50, 70, 40);
    tf2.borderStyle = UITextBorderStyleRoundedRect;
    [self.window2 addSubview:tf2];
    
    // 列印當前應用的主視窗,此時window2已經成為了應用的主視窗
    NSLog(@"%p", [UIApplication sharedApplication].keyWindow);
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // 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.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // 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.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // 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.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

相關推薦

ios-day11-01(UIWindow常用方法makeKeyWindowmakeKeyAndVisible獲取當前應用視窗所有視窗)

// // JLAppDelegate.h // 01-UIWindow // // Created by XinYou on 15-3-11. // Copyright (c) 2015ĺš´ vxinyou. All rights reserved. // #import @interfac

iOS基礎:NSArray常用方法

一、NSArray常用方法 //建立array + (instancetype)array; + (instancetype)arrayWithObject:(ObjectType)anObjec

正則表達中常用方法小結 test(),exec(),search(),match()區別及應用

今天覆習了一下正表示式物件的常用方法,對其中的細節進行總結了一下 下面詳細介紹一下各個方法的詳細使用 1 regExpObject.test(string value)    該

js 陣列操作常用方法 push():在陣列後面加入元素,並返回陣列的長度 unshif()t:在陣列前面加入元素,並返回陣列的長度 pop()刪除最後一個元素

var arr =[1,2,3,4,5] ; arr.push(6,7,8); console.log(arr);// push:在陣列後面加入元素   結果是:[1,2,3,4,5,6,7,8] arr aa = [7,8,9,0]; aa.unshift(4,5,6)

[轉]獲取當前執行腳本的方法

repr pri rip cnblogs ack rac lin int pat python __file__ 與argv[0] 在python下,獲取當前執行主腳本的方法有兩個:sys.argv[0]和__file__。 sys.argv[0] 獲取主執行文件路徑的

iOS 實時獲取當前應用消耗的CPU記憶體

https://www.cnblogs.com/mobilefeng/p/4977783.html 這一遍文章對獲取app 消耗的CPU和記憶體問題的多種方案做了對比,沒有實際去測試。 1 獲取應用消耗的CPU float cpu_usage() { kern_return

Laravel獲取當前請求的控制器方法以及中介軟體

laravel獲取請求路由對應的控制器和方法很簡單: 在任何地方都可以使用: dd(request()->route()->getAction()); 得到如下結果: arr

iOS獲取手機型號iOS獲取當前app的名稱版本號

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary); // app名稱 NSString *app_Name = [infoDi

iOS 獲取當前app的名稱版本號

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary); // a

iOS中如何通過點選UITableViewCell中的Button來獲取當前Cell的indexPath

- (void) btnOnClickTouched:(UIButton *)aButton { myTableViewCell* myCell = (myTableViewCell *)[aButton superView]; //表示Button新增在了Cell中。 //如果將Button新增在myCe

iOS開發基礎:OC數組對象NSArray的常用方法

indexof c語言 super main sset spa -- arr 初始 本文介紹了OC的數組對象的基本方法的使用: 因為OC的數組中存儲的為對象類型,所以我們可以新建一個Person類,通過Person生成對象進行操作。 其中Person.h中的代碼為: [o

01 NumPy 理解與ndarray建立多維陣列的常用方法與具體例項

NumPy get started 匯入numpy庫 import numpy as np 檢視版本 np.__version__ numpy核心其實就是一個 ndarray 多維陣列(演示 ndarray 輸出效果 以及 和 l

iOS常用方法——一個好用的獲取導航欄高度Tabbar高度的分類

開發中經常需要知道導航欄(系統)的高度和Tabbar的高度,一般是用來計算在ViewController中的位置和高度,我們可以寫一個UIVIewController的分類,這樣在呼叫的時候就很方便。程式碼如下: #import "UIViewController+MYViewCon

iOS常用方法——UIWebView全屏顯示的實現

專案中載入webView,導航欄由web端做的話,客戶端就需要隱藏掉導航欄。這個時候顯示出來的頁面,在頂部會出現狀態列為空白的問題。底部也會多出空白,即: - (void)viewDidLoad { [super viewDidLoad]; // Do any add

iOS 字串常用方法總結——不定時更新

                                                                                                     1.字串逆序排序: NSString *strs = @"ab

iOS字串分割常用方法

1.字串的替換: NSString *str=@"12334dllggg33dlrt "; str=[str stringByReplacingOccurrencesOfString:@"33"withString:@"hh"]; NSLog(@"%@",str)

進行前端效能優化幾種常用方法

程式碼層面:避免使用css表示式,避免使用高階選擇器,通配選擇器。 快取利用:快取Ajax,使用CDN,使用外部js和css檔案以便快取,新增Expires頭,服務端配置Etag,減少DNS查詢等 請求數量:合併樣式和指令碼,使用css圖片精靈,初始首屏之外的圖片資源

iOS常用方法——WKWebView與h5互動的實現

隨著前端開發的強大,原生與h5的互動用的也越來越多。 為什麼選用WKWebView,我們可以做一個對比,同一個web頁面,用UIWebView載入和用WKWebView來載入,記憶體佔用情況很容易看出來,回到原生頁面之後,UIWebView對應的記憶體也不會降

Build path 的重要安卓常用設定 讓 eclipse 下的 android 模擬器聯網沒有ADT的那個圖示顯示;模擬器路徑位置的更改方法

Build path 的重要。 The type java.lang.Object cannot be resolved.It is indirectly referenced 常看一下Build path中的各標籤中是否有錯誤選項(有紅叉),更正或刪除。 當從別處匯入新的專案時.ecl

iOS [UIApplication sharedApplication] openURL等常用方法使用例如:打電話定位等

1、打電話 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://電話號碼"]]; 2、發簡訊 [[UIApplication sharedApplication] openURL