-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawPatternLockView.m
executable file
·93 lines (68 loc) · 2 KB
/
DrawPatternLockView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// DrawPatternLockView.m
// AndroidLock
//
// Created by Purnama Santo on 11/2/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "DrawPatternLockView.h"
@implementation DrawPatternLockView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
if (!_trackPointValue)
return;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 10.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.5, 0.5, 0.5, 0.8};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGPoint from;
UIView *lastDot;
for (UIView *dotView in _dotViews) {
from = dotView.center;
//nslog(@"drwaing dotview: %@", dotView);
//nslog(@"\tdrawing from: %f, %f", from.x, from.y);
// //nslog(@"%g,%g", dotView.frame.origin.x, dotView.frame.origin.y);
if(from.y < 3)
continue;
if (!lastDot)
CGContextMoveToPoint(context, from.x, from.y);
else
CGContextAddLineToPoint(context, from.x, from.y);
lastDot = dotView;
}
CGPoint pt = [_trackPointValue CGPointValue];
//if(pt.x < 300 && pt.y < 420 && pt.y > 150)
//{
CGContextAddLineToPoint(context, pt.x, pt.y);
//}
//nslog(@"\t to: %f, %f", pt.x, pt.y);
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);
_trackPointValue = nil;
}
- (void)clearDotViews {
[_dotViews removeAllObjects];
}
- (void)addDotView:(UIView *)view {
if (!_dotViews)
_dotViews = [NSMutableArray array];
[_dotViews addObject:view];
}
- (void)drawLineFromLastDotTo:(CGPoint)pt {
_trackPointValue = [NSValue valueWithCGPoint:pt];
[self setNeedsDisplay];
}
@end