01-Common Files in projects (Launchscreen)
Xcode5 框架是苹果事先已经导入进去的.在项目的结构当中就能够看到导入的框架. Xcode6 会自动导入一些觉见的框架.在项目结构当中,看不到已经导入的框架. LaunchScreen.xib:用来设置启动界面.Xcode7 会自动导入一些觉见的框架.在项目结构当中,看不到已经导入的框架. LaunchScreen.storyBoard LaunchScreen原理: 会自动加载LaunchScreen是因为在Target当中,指定了Launch Screen file, 如果没有指定的话,就不会去加载LaunchScreen作为启动界面. 如果没有设置启动图片,模拟器默认的尺寸大小是4s的尺寸大小.(可以打印屏幕尺寸验证.) 模拟器默认的尺寸是由启动界面决定的. 它的底层实现其实把LaunchScreen上的东西,生成了一张图片,然后把这张图片设为程序的启动图片. 可以进入沙盒当中查看, 查看方法,找到应用程序根目录. 获取方法: NSLog(@"%@",NSHomeDirectory()); 打印出来,后前往文件夹.找到Library->Caches->Snapshots目录下面.最后一层就是程序自动生成的图片.
02-Common Files in projects (Info.plist)
?
Supporting file一般都是放些资源文件,像一些plist这些等.xcode5当中也有info.plist,只不过它的名字很长.是工程的名称.在xcode5当中,会自动生成一个pch文件,在Xcode6当中不会帮我们生成PCH文件.
?
info.plist当中保存着整个应用当中基本的配置.它是一个字典.查看它的类型.这个当中,主要掌握三个Key,Bundle Name:应用程序的名称.Bundle version string,short:应用程序的版本.在开发当中都是迭代开发.苹果要求下一次提交的版本必须得要比上一次提交的版本要高.
?
Bundle Version:应用程序编译的版本.Bundle identifier:应用程序标识符.保证应用程序的唯一性, 如果两个应用同一个标识符, 那么之前的那个应用会被干掉. 作用:上传到AppStore的时候必须得要有标识符. 当做推送的时候也必须得要Bundle identifier.Targets对应者info.plist.文件.
?
03-Common Files (PCH) in the project
?
PCH也是一个文件.一般PCH的名称跟项目的名称相同.PCH的作用:存放一些公用的宏. 存放一些公用的文件.只要在pch当中定义的东西, 会被整个应用程序共享.PCH它是一个预编译文件,要告诉系统要提前编译它.要去做一些配置.在Buld Setting 当中找perfix 找到Precomplie prefix Header 为yes.设完这些后,再进行prefix Header的路径配置.路径从根层开始.
?
1.定义一些常用公用的宏.经常做一些系统的版本号的宏,和一些屏幕的宏.
?
2.存放公用的头文件.分类的头文件3.pch可以自定义Log. 在宏当中,三个点...表示可变参数. 在函数当中,表示可变参数用:__VA_ARGS__ XMGLog(...) NSLog(__VA__ARGS__) 可以手动管理,直接注释掉. PCH:注意PCH会把它当中的所有内容导入到工程当中所有的文件.但如果工程当中有C语言文件的时候,它也是会把它给导入到C语言的文件当中.如果这样的话, 就会发生错误.????
?
解决办法:每一个OC文件都会定义一个__OBJC__宏,只要判断有没有定义这样一个宏, 就能看出是不是C语言的文件,如果没有定义这样的宏, 那就不需要导入这些东西.就不会报错.
04-uiapplication single case.
What is UIApplication? The UIApplication object is a symbol of the application. Each application has its own UIApplication object, an object that the system automatically creates for us, which is a singleton object. The first object created after an iOS program is launched is the UIApplication object, which we can only obtain by [UIApplication Sharedapplication], and cannot be created manually. uiapplication role? With UIApplication objects, you can perform some application-level operations. You can set the red reminder number in the upper-right corner of the application icon to set the visibility of the networking indicator to set the app's status bar to jump between apps. Imitation uiapplication single case. Requirements: The program creates the object as soon as it is started. The object created can only get objects by share. Cannot perform alloc operation, when executing ALLOC, the program crashes 1. The object is created when the program starts. The Load method is called when the class is loaded into memory, and it takes precedence over the static persion *_instance. + (void) load{you want to save the created object with member properties, but now it is a class method, there is no way to access member properties. So I got a static variable to save the created object _instance = [[Self alloc] init]; }2. Ensure that an exception is generated when calling Alloc. Rewrite the system is the Alloc method + (Instancetype) alloc{when the Alloc method is called, first look at the _instance there is no value, if there is already a value, throw an exception directly. if (_instance) {nsexception *exception = [nsexception exceptionwithname: @ "Nsint Ernalinconsistencyexception "Reason: @ "There can only be one persion instance." Userinfo:nil]; Throws an exception [exception raise]; } Keep the system in practice. return [Super Alloc]; } 3. Get Object + (Instancetype) sharepersion{return _instance} by share method
05-uiapplication function
1. Set app reminder number to get UIApplication object uiapplication *ap = [UIApplication sharedapplication]; Before setting up, to register a notification, from iOS8, you must first register a notification object. To be able to receive reminders. Uiusernotificationsettings *notice = [Uiusernotificationsettings Settingsfortypes:uiusernotificationtypebadge CA Tegories:nil]; Registering the Notification object [AP Registerusernotificationsettings:notice]; Set Reminder number Ap.applicationiconbadgenumber = 10;
2. Set the connection Status ap.networkactivityindicatorvisible = Yes;3. Sets the status bar of the application status bar, which is managed by default to the controller. The controller provides methods that can be overridden directly in the controller by setting the status bar style-(Uistatusbarstyle) preferredstatusbarstyle{return Uistatusbarstylelightcon Tent } Hides the status bar by way of the controller. Same implementation method: Returns no when no is hidden-(BOOL) prefersstatusbarhidden{return no; Often in development, applications are used to manage the status bar. To do unified management, otherwise, there will be a lot of controllers. It will be very troublesome. To have the application manage the status bar, configure it in Info.plist, add a key value: is the last one, the View controller-based status bar appearance is set to No. The application is managed.
Manage status with UIApplication. 1. Get uiapplication uiapplication *ap = [UIApplication sharedapplication]; 2. Set the status bar style. Ap.statusbarstyle = uistatusbarstylelightcontent; 3. Set the state of the hidden Ap.statusbarhidden = YES; 4. Jump page UIApplication *ap = [UIApplication sharedapplication]; URL: Protocol Header://Domain name application through the type of protocol header, to open the appropriate software. Nsurl *url =[nsurl urlwithstring:@ "http://www.baidu.com"]; [AP Openurl:url];
06-uiapplication the start-up process for agents and programs.
所有的移动操作系统都有个致命的缺点:app很容易受到打扰。比如一个来电或者锁屏会导致app进入后台甚至被终止还有很多其它类似的情况会导致app受到干扰,在app受到干扰时,会产生一些系统事件,这时UIApplication会通知它的delegate对象,让delegate代理来处理这些系统事件
?
delegate可处理的事件包括:应用程序的生命周期事件(如程序启动和关闭)系统事件(如来电)内存警告...
?
UIApplication会在程序一启动时候创建一个遵守UIApplicationDelegate代理.这个就是我们程序一创建时的AppDelegate类.AppDelegate就是遵守了UIApplicationDelegate协议.在这个类中很定义很多监听系统事件的方法.同时也定义了一些应用程序的生命周期方法.
?主要方法有:
应用程序的生命周期 应用程序启动完成的时候调用- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"%s",__func__); return YES;}
?
当我们应用程序即将失去焦点的时候调用- (void)applicationWillResignActive:(UIApplication *)application { NSLog(@"%s",__func__);}
?
当我们应用程序完全进入后台的时候调用- (void)applicationDidEnterBackground:(UIApplication *)application{ NSLog(@"%s",__func__);}
?
当我们应用程序即将进入前台的时候调用- (void)applicationWillEnterForeground:(UIApplication *)application { NSLog(@"%s",__func__);}
?
当我们应用程序完全获取焦点的时候调用 只有当一个应用程序完全获取到焦点,才能与用户交互.- (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"%s",__func__);}
?
当我们应用程序即将关闭的时候调用- (void)applicationWillTerminate:(UIApplication *)application { NSLog(@"%s",__func__);}2.应用程序的程动原理 程序启动时执行main函数,在main函数当中有以下操作. int main(int argc, char * argv[]) { @autoreleasepool { 第三个参数:UIApplication类名或者子类的名称 nil == @"UIApplication" 第四个参数:UIApplication的代理的代理名称 NSStringFromClass:把类名转化字符串 NSStringFromClass好处:1.有提示功能 2.避免输入错误 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
?
底层原理为: 1.根据principalClassName传递的类名创建UIApplication对象 2.创建UIApplication代理对象,给UIApplication对象设置代理 3.开启主运行事件循环,处理事件,保持程序一直运行. 4.加载info.plist,判断下是否指定main,如果指定了,就会去加载StoryBoard.
07-uiwindow
UIWindow是一种特殊的UIView,通常在一个app中至少有一个UIWindowiOS程序启动完毕后,创建的第一个视图控件就是UIWindow,接着创建控制器的view,最后将控制器的view添加到UIWindow上,于是控制器的view就显示在屏幕上了一个iOS程序之所以能显示到屏幕上,完全是因为它有UIWindow
?
在加载info.plist,判断下是否指定main,如果指定了,就会去加载StoryBoard. 1.创建一个窗口 2.加载MainStoryBoard,初始化一个控制器. 3.把初始化出来的控制器设置为窗口的根控制器.让窗口显示到屏幕上.如果没有指定Mian话, 那这个时候就需要我们手动的去创建窗口.当info.plist文件没有找到的时候,那么程序就加载完毕,那么在程序加载完毕时要自己手动去创建窗口.
在开发当中,通常都是手动去创建窗口.
? Add a window to the application that is based on the Alloc-init controller:
1.创建窗口,要有窗口显示,必须要有强引用.窗口也是控件,要想展示出来.必须得要有尺寸. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];2.创建控制器 会把控制器的View添加到窗口上.并且有一个旋转的功能. UIViewController *vc = [[UIViewController alloc] init]; vc.view.backgroundColor = [UIColor redColor];3.设置控制器为窗口的根控制器 self.window.rootViewController = vc;4.显示窗口 [self.window makeKeyAndVisible];
?
在设置rootViewController的时候,会把控制器的View添加到窗口上面.[self.window makeKeyAndVisible]的底层实现: 1.让窗口成为显示状态. 窗口默认是隐藏的.hidden = yes. 底层做的事件就是: self.window.hidden = NO; 2.把当前窗口设置成应用程序的主窗口 application.keyWindow获得应用程序的主窗口.
?
在程序当中,状态栏和键盘,它都属性是一个窗口.可以通过打印的方式来验证.设置window的层级.UIWindowLevelNormal它是一个CGFloat类型.self.window.windowLevel = UIWindowLevelNormalUIWindowLevelNormal < UIWindowLevelStatusBar < UIWindowLevelAlert
?
08-Load Controller from storyboard
1.创建窗口self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];2.加载控制器从StoryBoard当中加载控制器UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];加载剪头指向的控制器UIViewController *vc = [storyBoard instantiateInitialViewController];3.设置窗口根控制器self.window.rootViewController = vc;4.显示窗口[self.window makeKeyAndVisible];加载控制器的两种方式0.加载指定的StoryBoard.UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];1.加载箭头所指向的控制器.UIViewController *vc = [storyBoard instantiateInitialViewController];2.加载指定标识的控制器. UIViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"idCongtroler"];
?
09-Can over Xib load the controller's view
加载的步骤为:1.创建Xib2.往xib当中拖入一个控制器.3.设置Xib的file‘s owner类型为要设置的那个控制器.4.把View与file‘s owner连线. (注意, 只有设置了file‘s owner类型才能够进行拖线.)
?
initWithNibName:为要加载的Xib的名称. MyViewController *vc = [[MyViewController alloc] initWithNibName:@"VC" bundle:nil];
?
iOS--ui advanced-the first day of multi-controller management