IOS开发基础之手势解锁项目案例
项目最终实现效果。
由于缺少红色的error背景图。我自己从安卓项目找到一个手势解锁,然后通过ps添加粉红色的红圈,才得以解决。为了分享给大家源码,github和本地都进行了备份。项目才100K左右。最后用到了block回调思想或者设置代理的方式。
github源码地址:https://github.com/sunjunjunsun/Gesture-unlocking.git
CSDN资源地址:
https://download.csdn.net/download/A1521315qwss/15398441
具体的实现代码:
//
// ViewController.m
// 27-手势解锁
//
// Created by 鲁军 on 2021/2/20.
//
#import "ViewController.h"
#import "LJView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet LJView *passwordView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Home_refresh_bg"]];
self.passwordView.passwordBlock = ^(NSString * pwd) {
if([pwd isEqualToString:@"123"]){
NSLog(@"输入密码正确");
return YES;
}else
{
NSLog(@"输入密码错误");
return NO;
}
};
}
@end
// LJView.h
// 27-手势解锁
// Created by 鲁军 on 2021/2/20.
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface LJView : UIView
@property(nonatomic,copy) BOOL (^passwordBlock)(NSString *);
@end
NS_ASSUME_NONNULL_END
// LJView.m
// 27-手势解锁
// Created by 鲁军 on 2021/2/20.
#import "LJView.h"
#define kButtonCount 9
@interface LJView ()
@property(nonatomic,strong)NSMutableArray *btns;
//所有需要连线的数组
@property(nonatomic,strong)NSMutableArray *lineBtns;
@property(nonatomic,assign)CGPoint currentPoint