5、app启动流程、AppDelegate.m分析、xib介绍-OC+UI

来源:互联网 发布:软件疲劳强度测试 编辑:程序博客网 时间:2024/03/28 21:59

从用户点击,到整个应用程序起来样子。

app启动流程图

UIApplication生命周期

XIB(Interface builder)介绍


app启动流程图:

第4步:读到xib文件,归档,再将xib文件加载内存里面来

第5步:不是必要的操作。4.0后就没xib操作。

第7和6步:是同时操作,不是顺序


UIApplicationMain操作:


UIApplication生命周期 [整个应用程序的生命周期]

1、用户主动切换到后台

2、应用程序被电话、短信等中断

3、用户直接锁屏和解锁


AppDelegate代理函数:

进入后台状态:

1、即将进入后台

2、已经进入后台


AppDelegate.h文件下

<UIApplicationDelegate>是应用程序的生命周期协议

////  ccyAppDelegate.m//  UItest////  Created by ccy on 13-12-23.//  Copyright (c) 2013年 ccy. All rights reserved.//#import "ccyAppDelegate.h"@implementation ccyAppDelegate- (void)dealloc{    [_window release];    [super dealloc];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor redColor];        NSString * pathImage = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"png" inDirectory:@"images"];    NSLog(@"image:%@\n", pathImage);    pathImage = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"png"];    NSLog(@"image:%@\n", pathImage);    [self.window makeKeyAndVisible];    return YES;}//即将进入后台模式- (void)applicationWillResignActive:(UIApplication *)application{NSLog(@"function %@ is calling", NSStringFromSelector(_cmd));//_cmd即将被调用函数,打印出来信息是 function_applicationWillResignActive:is calling    // 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.//应用程序即将从活跃状态切换  到不活跃状态这个函数就被调用(消息)这也会在某些临时状态发生(比如来了电话,SMS短信) 或者 当用户退出应用程序,它开始切换到后台模式。  // 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.// 我们应该做什么?用这个方法我们要做暂停正在运行的任务。关闭定时器,降低opengls es的游戏帧率。暂停游戏。}//已经进入后台模式- (void)applicationDidEnterBackground:(UIApplication *)application{NSLog(@"function %@ is calling", NSStringFromSelector(_cmd));    // 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.//[这句话没什么意义]如果你的程序支持后台的话,这个程序就会被调用。applicationWillTerminate函数不支持后台的话,这个函数不会被调用。}//即将切换到前台的回调函数- (void)applicationWillEnterForeground:(UIApplication *)application{  NSLog(@"function %@ is calling", NSStringFromSelector(_cmd));  // 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.// 如果从背景模式切换到不活跃状态 这个函数会被调用// 在这里你可以做一些和之前进入后台相反的操作 恢复之前进入后天保存的内容}//程序已经切换到前台/Active模式- (void)applicationDidBecomeActive:(UIApplication *)application{NSLog(@"function %@ is calling", NSStringFromSelector(_cmd));    // 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.//重新启动被暂停的任务。如果应用程序在后台,那么这里就要刷新UI(user intaface)}- (void)applicationWillTerminate:(UIApplication *)application{NSLog(@"function %@ is calling", NSStringFromSelector(_cmd));    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground://当应用程序停止会调用这个函数 //但这个函数只有在 小于 ios4.0调用 或者 大于 ios4.0//设置了 不能后台模式调用 [测试的时候这只plist 中 这只不能运行于背景模式 application dose not run in backage YES]}//applicationDidReceiveMemoryWarning:接收到内存警告时调用[4.6版本没这个函数]@end



XIB(Interface builder)介绍

界面拖拽:[真正的企业开发并不使用]


xib 和 代码对比

1、快捷键方便 | 写程序慢

2、适合做静态页面 | 代码适合做复杂页面

3、不适合svn/git代码管理 |代码适合

4、不适合后期维护 | 代码适合长期维护

5、做外包可以一竿子,比较快。


工程代码实现

新建一个single View

第1个:文件说明

第2个:在线帮助文档

第3个:中有个class,界面要和类关联,KeyPath:是用于监听类中变量的变化过程

第4个:是界面的属性信息(底层颜色可以换)

第5个:界面宽度和高度

最后一个:图片和class类的关联情况


关联图标和代码:

对准图标按住ctrl + 拖动到代码处->事件action->命名

可以打开xib源代码就是xml格式。

////  ccyViewController.h//  XIBDemo////  Created by ccy on 13-12-24.//  Copyright (c) 2013年 ccy. All rights reserved.//// XIB(xml)--编译(序列化/归档)-->NIB(二进制xib)//NIB-->接档-->读入到程序中//灰色的表示self.view#import <UIKit/UIKit.h>@interface ccyViewController : UIViewController@end


0 0
原创粉丝点击