一个UI程序开始的代码函数导读

#import "QFAppDelegate.h"

@implementation QFAppDelegate

//最后一个执行的初始化函数
//主要做一些启动之前的初始化操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSLog(@"didFinishLaunchingWithOptions");
    
    //实例化窗口
    //initWithFrame 初始化位置和大小
    //[UIScreen mainScreen] 获取屏幕对象
    //[[UIScreen mainScreen] bounds] 获取屏幕边界,包含起始位置和屏幕大小
    //CGRect   矩形大小
    //CGPoint  坐标位置
    //CGSize   大小
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    //设置窗口背景颜色
    //UIColor 颜色对象
    self.window.backgroundColor = [UIColor whiteColor];
    //自定义颜色 RGBa
    //Red,Green,Blue 取值范围 0.0~1.0
    //Aplha 取值范围 0.0~1.0  0 为不透明
    UIColor *c = [UIColor colorWithRed:arc4random() % 256 / 255.0
                                 green:arc4random() % 256 / 255.0
                                  blue:arc4random() % 256 / 255.0
                                 alpha:1.0];
    
    self.window.backgroundColor = c;
    
    //显示窗口
    [self.window makeKeyAndVisible];
    
    //UIView
    //在屏幕上看得见摸得着的东西都是UIView的子类
    

    return YES;
}

//即将进入后台
//停止一些正在执行的操作
- (void)applicationWillResignActive:(UIApplication *)application
{
    NSLog(@"applicationWillResignActive");
    // 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.
}

//已经进入后台
//尽量多的保存app的当前状态
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    NSLog(@"applicationDidEnterBackground");
    // 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
{
    NSLog(@"applicationWillEnterForeground");
    // 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
{
    NSLog(@"applicationDidBecomeActive");
    // 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
{
    NSLog(@"applicationWillTerminate");
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

 

posted @ 2015-05-11 23:24  热血博  阅读(154)  评论(0编辑  收藏  举报