zoukankan      html  css  js  c++  java
  • 分析项目心得

    1.检查版本更新以及自动登录

    (1).宏定义

    (2)#define kBundle [NSBundle mainBundle].bundleIdentifier

    .检查版本更新

    在AppDelegate里面

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

     [self checkGuide];

    }

    (3)检查更新方法 

    //登录界面和首页的切换

    - (void)checkGuide

    {

        //版本号 新特性界面 是否应该加载

        //1.获取你app的版本号

        NSString *locaVerson = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];

        //2.获取 你保存在沙盒中的版本号    

        NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults];

        NSString *saveVersion = [defauts objectForKey:@"saveVerion"];

        //3.判断

        if([saveVersion isEqualToString:locaVerson]){//两者一致

          获取密码

           NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults];

           NSString *passWord = [defauts objectForKey:@"saveVerion"];

            if([defauts objectForKey:kUID] && [defauts objectForKey:kTOKEN]){

            //自动登录

                

                UUTabBarController * mainVc = [[UUTabBarController alloc]init];

                

                self.window.rootViewController = mainVc;

                

                

            }else{

            

    //        跳到登录界面

                //加载登录界面

                UUPhoNumLoginViewController * loginView=[[UUPhoNumLoginViewController alloc]init];

                

                UULoginNavController *mainVc=[[UULoginNavController alloc]initWithRootViewController:loginView];

                

                

                self.window.rootViewController = mainVc;

            

            }

        

          

            

        }else{

            

    #warning  把最新的版本号保存下来  ****新版本需要走引导页****

            

            [defauts setObject:locaVerson forKey:@"saveVerion"];

            

            [defauts synchronize];

            //加载登录界面

            UUPhoNumLoginViewController * loginView=[[UUPhoNumLoginViewController alloc]init];

            

            UULoginNavController *mainVc=[[UULoginNavController alloc]initWithRootViewController:loginView];

            

            self.window.rootViewController = mainVc;

        }

        

    }

    2.textField点击别处退出键盘

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

     [self.view endEditing:YES];

    }

    3.出来键盘,控制当前视图往上面移动的距离

     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeKeyBoard:) name:UIKeyboardWillShowNotification object:nil];

     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeKeyBoard:) name:UIKeyboardWillHideNotification object:nil];

    #pragma mark --相应键盘的通知事件

    - (void)changeKeyBoard:(NSNotification *)notification{

        if(self.passWordField){

        NSLog(@"%@",notification);

        //获取userInfo信息

        NSDictionary *userInfo = notification.userInfo;   

        //获取要移动控件的transForm

        CGAffineTransform transForm = self.view.transform;  

        //获取移动的位置 屏幕的高度 - 最终显示的frame的Y = 移动的位置

        //1. 获取键盘最终显示的y

        NSValue *value = userInfo[UIKeyboardFrameEndUserInfoKey];

        CGRect endFrame = [value CGRectValue];    

        CGFloat moveY = - (self.view.frame.size.height - endFrame.origin.y);   

        //移动具体移动多少,这里决定

        transForm = CGAffineTransformMakeTranslation(0, 移动的距离);

        //执行动画移动

        [UIView animateWithDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{       

            self.view.transform = transForm;

        }];

        }

    }

     4.控制进入一个控制器的导航栏视图的显示与隐藏

    -(void)viewWillAppear:(BOOL)animated{

        [super viewWillAppear:animated];

     self.navigationController.navigationBarHidden = YES;

    }

    -(void)viewWillDisappear:(BOOL)animated{

        [super viewWillDisappear:animated];

        self.navigationController.navigationBarHidden = NO;

    }

    5.在textField的里面的字体更改时就对自己的是有属性赋值

    [self.phoneNumField addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];

     [self.passWordField addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];

    -(void)textChange{

        self.userName=self.phoneNumField.text;

        self.passWord=self.passWordField.text;

    }

    6.获取验证码textField的编写

     UITextField * phoneNumField=[[UITextField alloc]init];

     self.phoneNumField= phoneNumField;

     self.phoneNumField.borderStyle= UITextBorderStyleRoundedRect;

     self.phoneNumField.clearButtonMode = UITextFieldViewModeAlways;  

        UILabel * phoneNumLable = [[UILabel alloc]init];

        UIFont *iconfont = [UIFont fontWithName:@"IconFont" size: 18];

        phoneNumLable.font = iconfont;

        phoneNumLable.text = @"U0000e602"; 

        UIView *phoneNumview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 50)];

        self.phoneNumField.leftView=phoneNumview;

        self.phoneNumview = phoneNumview ;

        phoneNumLable.frame = CGRectMake(10, 0, 30, 50);

        [self.phoneNumview addSubview:phoneNumLable];   

        self.phoneNumField.leftViewMode = UITextFieldViewModeAlways;

    UITextField * passWordField=[[UITextField alloc]init];

        self.passWordField= passWordField;

        self.passWordField.placeholder=@"验证码";

       UIButton * verCodeBtn = [[UIButton alloc]init];

        self.passWordField.rightView = verCodeBtn;

        self.passWordField.rightViewMode = UITextFieldViewModeAlways;

    注解:iconfont图标示例

    这样,我们就可以很方便的使用iconfont图标了。这里要注意的是,图标是用的iconfont中的图标用的是unicode编码,我们在自己的工程中时需要将&#xXXXX格式转换成UXXXXXXXX格式。

    -(void)loadView{
        [super loadView];
    //    imageView
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 50, 30, 30)];
        [self.view addSubview:imageView];
    //图标编码是&#xe603,需要转成U0000e603
        imageView.image = [UIImage iconWithInfo:TBCityIconInfoMake(@"U0000e603", 30, [UIColor redColor])];
    //    button
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(100, 100, 40, 40);
        [self.view addSubview:button];
        [button setImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"U0000e60c", 40, [UIColor redColor])] forState:UIControlStateNormal];
    //    label,label可以将文字与图标结合一起,直接用label的text属性将图标显示出来
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 160, 280, 40)];
        [self.view addSubview:label];
        label.font = [UIFont fontWithName:@"iconfont" size:15];//设置label的字体
        label.text = @"这是用label显示的iconfont  U0000e60c";
    }

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor whiteColor];
        self.navigationController.navigationBar.translucent = NO;
    
        UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithImage:[ UIImage iconWithInfo:TBCityIconInfoMake(@"U0000e602",22,[UIColor colorWithRed:0.55 green:0.55 blue:0.55 alpha:1])] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction)];
        self.navigationItem.leftBarButtonItem = leftBarButton;
    
    
        self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:0.55 green:0.55 blue:0.55 alpha:1];
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"U0000e60d",25, [UIColor colorWithRed:0.14 green:0.61 blue:0.83 alpha:1.00])] style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonAction)];
         self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:0.14 green:0.61 blue:0.83 alpha:1.00];
    
        // Do any additional setup after loading the view, typically from a nib.
    }
    

     

    6.获取系统的相关信息

     //获取你app的版本号

        NSString *locaVerson = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];

     //    手机系统版本

        NSString * iponeM = [[UIDevice currentDevice] systemName];

    7.获取手机的型号

    /** 设备类型 */

    #define kDevice_iPhone4 (kScreenHeight <= 480.0)   //包括iPhone4 , iPhone4s

    #define kDevice_iPhone5 ((kScreenHeight > 480.0) && (kScreenHeight <= 568.0))   //包括iPhone5,iPhone5s

    #define kDevice_iPhone6 ((kScreenHeight > 568.0) && (kScreenHeight <= 667.0))   //iPhone6

    #define kDevice_iPhone6Plus ((kScreenHeight > 667.0) && (kScreenHeight <= 736.0))   //iPhone6Plus

    8.跳转登录可以直接通过

    [UIApplication sharedApplication].keyWindow.rootViewController = mainVc进行设置

     9.自定义的相应是控件可以继承自UIControl

    10.使用蒲公英可以快速获取设备的UUID

    11.UIView类的autoresizingMask

    在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高。

    enum {

       UIViewAutoresizingNone                 = 0,

       UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,

       UIViewAutoresizingFlexibleWidth        = 1 << 1,

       UIViewAutoresizingFlexibleRightMargin  = 1 << 2,

       UIViewAutoresizingFlexibleTopMargin    = 1 << 3,

       UIViewAutoresizingFlexibleHeight       = 1 << 4,

       UIViewAutoresizingFlexibleBottomMargin = 1 << 5

    };

    UIViewAutoresizingNone就是不自动调整。

    UIViewAutoresizingFlexibleLeftMargin 自动调整与superView左边的距离,保证与superView右边的距离不变。

    UIViewAutoresizingFlexibleRightMargin 自动调整与superView的右边距离,保证与superView左边的距离不变。

    UIViewAutoresizingFlexibleTopMargin 自动调整与superView顶部的距离,保证与superView底部的距离不变。

    UIViewAutoresizingFlexibleBottomMargin 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。

    UIViewAutoresizingFlexibleWidth 自动调整自己的宽度,保证与superView左边和右边的距离不变。

    UIViewAutoresizingFlexibleHeight 自动调整自己的高度,保证与superView顶部和底部的距离不变。

    12.使用JSON进行JSON支持

    地址:http://stig.github.com/json-framework/

    JSON框架。包括一个解析器将JSON字符串解析成对象;以及一个生成器从对象生成字符串。

    // JSON string -> NSDictionary    

    NSString *jsonString = @"{"foo": "bar"}";     

    NSDictionary *dictionary = [jsonString JSONValue];    

    NSLog(@"Dictionary value for "foo" is "%@"", [dictionary objectForKey:@"foo"]);     

    // NSDictionary -> JSON string     

    NSString *newJsonString = [dictionary JSONRepresentation]; 

    13.快速定义的小技巧。其最新的Swift里面已经集成了

    #define Color(a) [UIColor colorForHex:a]

    #define IMAGE(a) [UIImage imageNamed:a]

    14.项目里面尽量多使用懒加载的形式:数组,自定义view 控件的创建

    例如:懒加载的代码写到一起,还可以增加了可读性

    //导航栏左按钮

    - (UIBarButtonItem *)leftItem{

        if (!_leftItem) {

            _leftItem = [[UIBarButtonItem alloc]initWithImage:IMAGE(@"back") style:UIBarButtonItemStylePlain target:self action:@selector(backMethod)];

            [_leftItem setTintColor:WHITECOLOR];

        }

        return _leftItem;

    }

    - (UIBarButtonItem *)rightItem{

        if (!_rightItem) {

            _rightItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStyleDone target:self action:@selector(registerMethod)];

            [_rightItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateNormal];

            [_rightItem setTintColor:WHITECOLOR];

        }

        return _rightItem;

    }

    15.创建圆角的button

    [UIButton buttonWithType:UIButtonTypeRoundedRect];

    16.创建一个随机的颜色,一般使用来进行测试

    #define RandomColor [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1]

     17.使用类似闭包的形式添加控件,更加的简洁:

    闭包式

     UIView *backView = [[UIView alloc]initWithFrame:(CGRect){0,0,K_ZY_SCREEM_WIDTH,64}];

         [self.view addSubview:(

          backView.backgroundColor = [UIColor lightGrayColor],

          backView

          )];

        //  返回按钮

        UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        

       

         

        [backView addSubview:(

            backBtn.frame = (CGRect){0,20,40,40},

            [backBtn setImage:[UIImage imageNamed:@"返回Btn"] forState:UIControlStateNormal],,

            [backBtn addTarget:self action:@selector(OnTapBackBtn:) forControlEvents:UIControlEventTouchUpInside],

            backBtn

         )];

    18.使用枚举的形式创建一个通用的类,可以使用定义局部变量的形式,局部变量的类型是bool,通过判断枚举的属性type的值,对当前的类进行不同的设置,以达到一个类不同显示的实现

    BOOL disableBarScroll = _type == STControllerTypeDisableBarScroll;

    BOOL hiddenNavigationBar = _type == STControllerTypeHiddenNavBar;

    根据局部属性进行不同的设置即可

    19.

    //去掉过期警告

    #pragma clang diagnostic push

    #pragma clang diagnostic ignored "-Wdeprecated-declarations"

    // 这部分使用到的过期api

    #pragma clang diagnostic pop

    20.使用weak进行引用的特点

    weak reference"的property,他的特色就是虽然会持有对方的reference,但是不会增加retain count

  • 相关阅读:
    敏捷开发第五天
    敏捷开发第四天
    系统用户分析模型
    第三天敏捷开发
    第二天敏捷开发
    敏捷开发第一天
    第三周学习总结
    [学习笔记]莫队算法
    【网络流】Modular Production Line
    [学习笔记]set的使用
  • 原文地址:https://www.cnblogs.com/chaoyueME/p/5938058.html
Copyright © 2011-2022 走看看