zoukankan      html  css  js  c++  java
  • UIApplication

    1、Application 相关方法

    /************ 运行程序时,必须执行的方法(程序入口) *****************************************/
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        // Override point for customization after application launch.
        return YES;
    }
    
    /************ 当前应用程序将要进入非活动状态(进入后台)(Will, Should 将要的意思) *****************************************/
    - (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.
        */
    }
    
    /************ 当前程序已经进入后台(Did 已经的意思) *****************************************/
    - (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:.
        */
    }
    
    /************ 内存紧张 *****************************************/
    - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    
        // try to clean up as much memory as possible. next step is to terminate app
    }
    

    2、main 方法

    int main(int argc, char * argv[]) {
    
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    }
    
    • 作用:main 函数中只调用了一个 UIApplicationMain 的函数,整个程序的入口可以认为从 main 交给了 UIApplicationMain 函数。
    • 函数原型:
    UIKIT_EXTERN int UIApplicationMain(int argc, 
                                     char *argv[], 
                                 NSString * __nullable principalClassName, 
                                 NSString * __nullable delegateClassName);
    
    • argc, argv[]:与 main 的两个参数相同,一个是整形,一个是指针数组。
    • principalClassName:委托方类名,这个类实时检测当前程序的运行状态,这个参数一定要是 UIApplication 类或其子类,如果参数为空 nil,默认为 UIApplication 。
    • delegateClassName:代理方类名,遵守 UIApplicationDelegate 协议,实现协议中的方法,当第三个参数中的委托方检测到当前程序状态改变时会委托第四个参数在状态改变时执行相应的操作。

    3、状态栏的设置

    // 获取状态栏高度
    // returns CGRectZero if the status bar is hidden,默认高度为 20.0
    CGFloat height = [UIApplication sharedApplication].statusBarFrame.size.height;
    
    // 显示/隐藏状态栏
    /*
        需在 Info.plist 添加 key:View controller-based status bar appearance,value:NO
    
        statusBarHidden:YES 隐藏,NO 显示(默认)
    */
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    // 设置状态栏颜色
    /*
        需在 info.plist 添加 key:View controller-based status bar appearance,value:NO
        在 iOS7 版本以前直接设置就可以
    
        UIStatusBarStyleDefault      = 0, Dark content, for use on light backgrounds  黑色内容,默认
        UIStatusBarStyleLightContent = 1, Light content, for use on dark backgrounds  白色内容
    */
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;    
    

    4、状态栏上网络状态风火轮的设置

    // 风火轮旋转状态设置
    // YES 开始旋转,NO 停止旋转(默认),停止时自动隐藏
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
  • 相关阅读:
    Spring基础学习
    云服务器配置java环境
    Struts2学习笔记(一)--入门常见配置
    Hibernate学习笔记(二)
    Hibernate学习笔记(一)
    java---Listener & Filter知识点学习
    java----DBUtils知识点补充
    java----连接池C3p0使用的补充
    IOS之表视图单元格删除、移动及插入
    IOS之表视图添加索引
  • 原文地址:https://www.cnblogs.com/CH520/p/9375271.html
Copyright © 2011-2022 走看看