day 020 Pinunlock NavigationController

#import "AppDelegate.h"
#import "PINUnlockViewController.h"


@interface AppDelegate ()


@end


@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //创建PIN解锁界面
    PINUnlockViewController *puvc = [[PINUnlockViewController alloc] init];
    
    //配置windows的启动界面为PIN解锁
    self.window.rootViewController = puvc;
    
    return YES;

}

@end


//
//  PINUnlockViewController.m
//  PrivateAlbum
//
//  Created by Pengxiaodong on 15/4/14.
//  Copyright (c) 2015年 Pengxiaodong. All rights reserved.
//


#import "PINUnlockViewController.h"
#import "Utilities.h"


#define kPasswordKey @"passwordKey"


@interface PINUnlockViewController ()
@property (nonatomic, strong) UILabel *alertLabel;
@property (nonatomic, strong) UITextField *inputTextField;
@property (nonatomic, strong) UITextField *showingTextField;
@property (nonatomic, strong) NSUserDefaults *userDefaults;
@property (nonatomic, strong) NSString *password;
@property (nonatomic, strong) NSString *tempPassword;
@end


@implementation PINUnlockViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化界面
    [self initial];
}


- (void)initial{
    //读取本地图片
    UIImage *bgImage = [UIImage imageNamed:@"Main_BG"];
    
    //设置背景图片
    self.view.backgroundColor = [UIColor colorWithPatternImage:bgImage];
    
    //创建导航条视图
    [Utilities createImageViewWithFrame:CGRectMake(0, 20, 320, 47) andImageName:@"NavigationBar_BG" superView:self.view];
    
    //创建标题视图
    [Utilities createImageViewWithFrame:CGRectMake(100, 34, 120, 19) andImageName:@"NavigationBar_Logo" superView:self.view];
    
    //创建提示的文本框 UILabel
    self.alertLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 108, 320, 50)];
    _alertLabel.textAlignment = NSTextAlignmentCenter;
    _alertLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_alertLabel];
    
    //判断启动之后提示的内容
    self.userDefaults = [NSUserDefaults standardUserDefaults];
    
    //获取本地保存的密码
    self.password = [_userDefaults objectForKey:kPasswordKey];
    if (_password.length == 0) {
        //第一次登陆
        _alertLabel.text = @"请设置密码";
    } else{
        _alertLabel.text = @"请输入密码";
    }
    
    
    [Utilities createImageViewWithFrame:CGRectMake(31, 178, 257, 82) andImageName:@"Unlock_PINCode1_Normal" superView:self.view];
    
    self.view.userInteractionEnabled = NO;
    
    //创建用来显示的TextField
    self.showingTextField = [[UITextField alloc] initWithFrame:CGRectMake(91, 178, 197, 82)];
    _showingTextField.textColor = [UIColor whiteColor];
    _showingTextField.font = [UIFont systemFontOfSize:30];
    _showingTextField.secureTextEntry = YES;
    [self.view addSubview:_showingTextField];
    
    //创建一个用来接受用户输入的TextField
    self.inputTextField = [[UITextField alloc] initWithFrame:CGRectZero];
    _inputTextField.delegate = self;
    [self.view addSubview:_inputTextField];
    [_inputTextField becomeFirstResponder];


}


#pragma mark --- UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    /*
     textField.text 输入之前显示的内容
     range  替换的字符的范围location,lenth (1 ,1)
     string 目前输入的字符 或者是@""
     */
    //获取当前应该显示的内容
    NSString *contentString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
    //将内容显示
    _showingTextField.text = contentString;
    
    return YES;
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    //判断是不是第一次登陆
    if (_password.length == 0) {
        if (_tempPassword.length == 0) {
            //第一次设置密码
            self.tempPassword = textField.text;
            
            _alertLabel.text = @"请确认密码";
        }else{
            if ([_tempPassword isEqualToString:textField.text]) {
                _alertLabel.text = @"密码设置成功";
                
                [_userDefaults setObject:_tempPassword forKey:kPasswordKey];
            }else{
                _alertLabel.text = @"两次输入不一致 重新设置";
                
                self.tempPassword = @"";
                
            }
        }
    } else {
        //不是第一次登陆,在输入解锁密码
        if ([textField.text isEqualToString:_password]){
            //输入密码正确
            _alertLabel.text = @"密码正确";
        } else {
            _alertLabel.text = @"密码错误 请重新输入";
            
        }
    }
    
    _showingTextField.text = @"";
    _inputTextField.text = @"";
    return YES;
}
@end

#import "Utilities.h"


@implementation Utilities


//创建背景图片视图
+ (UIImageView *)createImageViewWithFrame:(CGRect)rect andImageName:(NSString *)imageName superView:(UIView *)superView{
    UIImageView *tempImageView = [[UIImageView alloc] initWithFrame:rect];
    tempImageView.image = [UIImage imageNamed:imageName];
    [superView addSubview:tempImageView];
    
    return tempImageView;
}


@end

实现Pinunlock,与滑动解锁相同的部分提取函数到Utilities中

在实现输入输出时,用两个uitextfiled,一个作为show,一个作为input,注意其出现的次序,使用代理
//  PINUnlockViewController.h
//  PrivateAlbum




#import <UIKit/UIKit.h>


@interface PINUnlockViewController : UIViewController<UITextFieldDelegate>


@end




NavigationController切换页面,两种方法


//
//  AppDelegate.m
//  NavigationController
//
//  Created by 蔡定龙 on 15-4-13.
//  Copyright (c) 2015年 李灵杰. All rights reserved.
//


#import "AppDelegate.h"
#import "ViewController.h"


@interface AppDelegate ()
            


@end


@implementation AppDelegate
            


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //创建一个导航栏
    
    //为导航栏创建一个界面
    ViewController *vc = [[ViewController alloc]init];
    //将界面作为导航栏控制器的主界面
    UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:vc];
    //将导航栏控制器设置为window的启动界面
    self.window.rootViewController = nvc;
    
    
    return YES;
}



@end


//
//  ViewController.m
//  NavigationController
//
//  Created by 蔡定龙 on 15-4-13.
//  Copyright (c) 2015年 李灵杰. All rights reserved.
//


#import "ViewController.h"
#import "SecondViewController.h"


@interface ViewController ()
            


@end


@implementation ViewController
            
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor redColor];
    UIButton *button =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(0, 100, 200, 200);
    [button setTitle:@"next" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(changetoNext) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




- (void)changetoNext{
    SecondViewController *svc = [[SecondViewController alloc]init];
    [self.navigationController pushViewController:svc animated:YES];
    //[self presentViewController:svc animated:YES completion:nil];
}
@end


//
//  SecondViewController.m
//  NavigationController
//
//  Created by 蔡定龙 on 15-4-14.
//  Copyright (c) 2015年 李灵杰. All rights reserved.
//


#import "SecondViewController.h"




@interface SecondViewController ()


@end


@implementation SecondViewController


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(100, 200, 120, 50);
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(comeBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}


- (void)comeBack{
    //push pop
    //[self.navigationController popViewControllerAnimated:YES];
    
    //model dismiss
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    //[self dismissViewControllerAnimated:YES completion:nil];
}


/*
#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值