iOS基礎(一)

UIKIT框架

  • UIView是視圖的基類
  • UIViewController視圖控制器的基類
  • UIResponder表示一個能夠接受觸摸屏上觸摸事件的對象
  • UIWin(窗口)是視圖的一個子類,窗口的主要功能:一、提供一個區域來顯示視圖,二、將事件(event)分發給視圖。
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen] bounds];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

UIScreen

  • UIScreen對象能夠充當iOS設備物理屏幕的替代者,經過[[UIScreen mainScreen] bounds]能夠得到設備的屏幕大小

UIWindow

  • 經過UIApplication獲取當前keyWindow,keyWindow是用來管理鍵盤以及觸摸類的消息,而且只能有一個window是keyWindow.
  • UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
  • 每一個UIWindow對象配置windowLevel屬性,大部分時候不該該去改變windowL.
  • UIWindow有3個級別,對應了3種顯示優先級。經過windowLevel設置,優先級爲:UIWindowLevel > UIWindowLevelStatusBar > UIWindowLevelNormal
//didFinishLauchingWithOptions
    self.windonw = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScrren] bounds]];
    self.window.backgrondColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    NSLog(@"self.window level: %@",self.windonw.level);

    UIButton *startButton = [UIButton buttonWithType:UIButtonTypeRounedRect];
    startButton.frame = CCRectMake(320/2-120/2,180,120,35);
    [startButton setTile:@"警告" action:@selector(alertUser) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:startButton];

    return YES;
// alerUser
    -(void)alertUser
    {
        UIAlertView *alertView = [[UIAlertView alloc]
                                    initWithTitle:@"提示"
                                    message:@"警告框是alert Level級別的"
                                    delegate:nil
                                    cancelButtonTitle:@"肯定"
                                    otherButtonTitles:nil];
        [alertView show];
    }
相關文章
相關標籤/搜索