-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDrawPatternLockView.m
More file actions
executable file
·89 lines (65 loc) · 1.88 KB
/
DrawPatternLockView.m
File metadata and controls
executable file
·89 lines (65 loc) · 1.88 KB
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
//
// 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
{
NSLog(@"drawrect...");
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);
if (!lastDot)
CGContextMoveToPoint(context, from.x, from.y);
else
CGContextAddLineToPoint(context, from.x, from.y);
lastDot = dotView;
}
self.lastSelectedDot = lastDot;
CGPoint pt = [_trackPointValue CGPointValue];
NSLog(@"\t to: %f, %f", pt.x, pt.y);
CGContextAddLineToPoint(context, 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];
if (view != nil)
[_dotViews addObject:view];
}
- (void)drawLineFromLastDotTo:(CGPoint)pt {
_trackPointValue = [NSValue valueWithCGPoint:pt];
[self setNeedsDisplay];
}
@end