IOS 手势解锁

fssssssss 2014-12-09 03:25:58
请教
想做一个IOS的 手势解锁 加密的界面(支付宝手势滑动解锁那种 )

自己开发的话,也可以,自己绘制界面之类的。

可是小弟 觉得,这个在IOS里应该挺常用的,是否有相关的库可以使用。或者是否有开源项目可以借鉴。

求提供关键字

谢啦
...全文
150 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fssssssss 2014-12-10
  • 打赏
  • 举报
回复
分享一下code,写的不是很优美,不过能用 @interface SettingViewController () { } @property (strong) UIImageView *backView; @property (strong) NSMutableArray *pointArr; @property (strong) NSMutableArray *keyArr; @property (strong) NSString *rightKeyString; @end @implementation SettingViewController - (id)init { self = [super init]; if (self) { _pointArr = [[NSMutableArray alloc]initWithCapacity:9]; _keyArr = [[NSMutableArray alloc]initWithCapacity:9]; _rightKeyString = @"14678"; } return self; } -(BOOL)shouldAutomaticallyForwardRotationMethods { return NO; } - (void)loadView { [super loadView]; CGRect bounds = [[UIScreen mainScreen] applicationFrame]; bounds = bounds; //View //self.view = [[UIView alloc] initWithFrame:bounds]; self.view.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:1]; //back _backView=[[UIImageView alloc] initWithFrame:self.view.frame]; [self.view addSubview:_backView]; //other float begin_x = bounds.size.width/4; float begin_y = bounds.size.height/4; float inteval = bounds.size.width/4; float point_radius = bounds.size.width/16; for(int iY=0;iY<3;iY++) { for(int iX=0;iX<3;iX++) { UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,point_radius*2, point_radius*2)]; [img setCenter:CGPointMake(begin_x+inteval*iX , begin_y+inteval*iY)]; [_pointArr addObject:img]; [self.view addSubview:img]; } } } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touches Began"); [_keyArr removeAllObjects]; //CGPoint startPoint = [self getCurrentPoint:touches]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint movePoint = [self getCurrentPoint:touches]; NSUInteger indexTouched = [self touchPoint2Index:movePoint]; if(indexTouched!=-1) { [self addtoKeyArr:indexTouched]; } //DrawLines and change png [self drawUI]; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if(_keyArr.count<1) return; CGPoint endPoint = [self getCurrentPoint:touches]; NSLog(@"x:%f ; y:%f",endPoint.x,endPoint.y); NSString *strKeyInput = @""; for(int i=0;i<_keyArr.count;i++) { strKeyInput = [strKeyInput stringByAppendingString:[_keyArr objectAtIndex:i]]; } if([strKeyInput isEqual:_rightKeyString]) { [GeneralFunction.inst AlertTemporayString:@"Success" tick:0.5f]; } else { [GeneralFunction.inst AlertString:@"Fail,Please Retry"]; } [self ClearKeyScreen]; } -(CGPoint)getCurrentPoint:(NSSet*)touches { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:touch.view]; return point; } -(void)addtoKeyArr:(NSUInteger)val { NSString *str = [NSString stringWithFormat:@"%d",val]; if(![_keyArr containsObject:str]) { [_keyArr addObject:str]; } //test NSString *strKey = @""; for(int i=0;i<_keyArr.count;i++) { strKey = [strKey stringByAppendingString:[_keyArr objectAtIndex:i]]; } NSLog(@"%@",strKey); } -(NSUInteger)touchPoint2Index:(CGPoint)movePoint { for(int i=0;i<_pointArr.count;i++) { UIImageView *img = [_pointArr objectAtIndex:i]; CGRect r = img.frame; if(r.origin.x < movePoint.x && r.origin.y < movePoint.y && r.size.width+r.origin.x > movePoint.x && r.size.height+r.origin.y > movePoint.y ) { return i; } } return -1; } -(void)drawUI { //change png for(int i=0;i<_keyArr.count;i++) { NSString *strKey = [_keyArr objectAtIndex:i]; int iKey = strKey.intValue; UIImageView *imgView = [_pointArr objectAtIndex:iKey]; [imgView setImage:[UIImage imageNamed:@"point_2.png"]]; } //draw lines if(_keyArr.count>1) { UIGraphicsBeginImageContext(_backView.frame.size); CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 4.0); //线宽 CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 1.0, 1.0); //颜色 CGContextBeginPath(UIGraphicsGetCurrentContext()); // CGContextClearRect(UIGraphicsGetCurrentContext(), _backView.frame); for(int i=0;i<_keyArr.count-1;i++) { NSString *strKey1 = [_keyArr objectAtIndex:i]; int iKey1 = strKey1.intValue; UIImageView *imgView1 = [_pointArr objectAtIndex:iKey1]; CGFloat x1 = imgView1.center.x; CGFloat y1 = imgView1.center.y; NSString *strKey2 = [_keyArr objectAtIndex:i+1]; int iKey2 = strKey2.intValue; UIImageView *imgView2 = [_pointArr objectAtIndex:iKey2]; CGFloat x2 = imgView2.center.x; CGFloat y2 = imgView2.center.y; CGContextMoveToPoint(UIGraphicsGetCurrentContext(), x1, y1); //起点坐标 CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), x2, y2); //终点坐标 CGContextStrokePath(UIGraphicsGetCurrentContext()); } _backView.image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } } -(void)ClearKeyScreen { //Reset Point for(NSUInteger i=0;i<_pointArr.count;i++) { UIImageView *imgEle = [_pointArr objectAtIndex:i]; [imgEle setImage:[UIImage imageNamed:@"point_1.png"]]; } //Clear Screen UIGraphicsBeginImageContext(_backView.frame.size); CGContextClearRect(UIGraphicsGetCurrentContext(), _backView.frame); _backView.image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self ClearKeyScreen]; } @end
fssssssss 2014-12-10
  • 打赏
  • 举报
回复
找了找 ,后来发现其实自己实现也蛮简单,也就200多行代码 麻烦大家了 。
不担心 2014-12-09
  • 打赏
  • 举报
回复
http://code4app.com/ios/Pattern-Lock-App/4f9795e506f6e7f068000000

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧