手势密码源码

//
//  WPSignPasswordView.h
//  网投网
//
//  Created by wangtouwang on 15/4/9.
//  Copyright (c) 2015年 wangtouwang. All rights reserved.
//

#import 

@class  WPSignPasswordView;
@protocol WPSignPasswordDelegate 

//设置密码 确认成功
@required
-(void)setPawSuccess:(NSString *)password;
//设置第一次临时密码成功
@required
-(void)setFirstPasswordSuccess:(NSString *)password;
//第二次输入确认密码错误
-(void)setTwoPasswordError;
//修改手势密码 请输入之前的密码
-(void)setSuccessAfterFirstPS:(NSString *)password;
//进入程序后输入手势密码判断是否正确
-(void)confirmPassword:(NSString *)password;
//手势密码进入修改状态(即原密码输入成功) 首次输入
-(void)updateSPFirst:(NSString *)password;
//手势密码进入修改状态(即原密码输入成功) 二次输入,相当于输入密码确认
-(void)updateSPConfirm:(NSString *)password;

@end

#pragma mark 手势密码View
@interface WPSignPasswordView : UIView


//设置代理
@property(nonatomic,strong) id spDelegate;

@end
复制代码
复制代码
//
//  WPSignPasswordView.m
//  网投网
//
//  Created by wangtouwang on 15/4/9.
//  Copyright (c) 2015年 wangtouwang. All rights reserved.
//

#import "WPSignPasswordView.h"


//屏幕的长宽
#define KSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define KSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height



@interface WPSignPasswordView()
{
    
}

@property(nonatomic,strong) NSMutableArray *stringArrays;
@property(nonatomic,strong) NSMutableArray *allButtonsArray;
//定义一个属性,记录当前点
@property(nonatomic,assign)CGPoint currentPoint;

@end

@implementation WPSignPasswordView


#pragma mark 实例化收集字符串的数组 并且用懒加载
-(NSMutableArray *)getStringArrays{
    if (self.stringArrays==nil) {
        self.stringArrays = [NSMutableArray array];
    }
    return  self.stringArrays;
}

#pragma mark 实例化包含所有密码按钮的数组 并且用懒加载
-(NSMutableArray *)getAllButtonsArray{
    if (self.allButtonsArray==nil) {
        self.allButtonsArray = [NSMutableArray array];
    }
    return self.allButtonsArray;
}

#pragma mark 复写初始化界面函数 initFrame
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

#pragma mark 界面布局
-(void)setup{
    //NSLog(@"初始化界面布局执行的");
    for (int index=1; index<=9; index++) {
        //创建按钮
        UIButton *numberButton = [[UIButton alloc] init];
        //设置按钮的背景图片,并且设置是在何种状态下
        [numberButton setBackgroundImage:[UIImage imageNamed:@"gesture_node_normal"] forState:UIControlStateNormal];
        [numberButton setBackgroundImage:[UIImage imageNamed:@"gesture_node_highlighted"] forState:UIControlStateSelected];
        //将按钮添加到视图中
        [self addSubview:numberButton];
        //将按钮存储到按钮数组中
        [[self getAllButtonsArray] addObject:numberButton];
        //禁止按钮点击事件
        numberButton.userInteractionEnabled=NO;
        //设置按钮标志值
        numberButton.tag=index;
        
    }
}

#pragma mark 看看何时触发
-(void)layoutSubviews{
    //需要先调用父类的方法
    [super layoutSubviews];
    //设置按钮位置
    for (int index=0; index 
   

转载于:https://www.cnblogs.com/android-dev/p/4517930.html

你可能感兴趣的:(手势密码源码)