分析项目心得
Posted 超越ME
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分析项目心得相关的知识,希望对你有一定的参考价值。
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;
[email protected]"验证码";
UIButton * verCodeBtn = [[UIButton alloc]init];
self.passWordField.rightView = verCodeBtn;
self.passWordField.rightViewMode = UITextFieldViewModeAlways;
这样,我们就可以很方便的使用iconfont图标了。这里要注意的是,图标是用的iconfont中的图标用的是unicode编码,我们在自己的工程中时需要将&#xXXXX格式转换成\UXXXXXXXX格式。
-(void)loadView{
[super loadView];
// imageView
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 50, 30, 30)];
[self.view addSubview:imageView];
//图标编码是,需要转成\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.
}
以上是关于分析项目心得的主要内容,如果未能解决你的问题,请参考以下文章