-
Notifications
You must be signed in to change notification settings - Fork 12
/
NRWindow.m
70 lines (62 loc) · 1.87 KB
/
NRWindow.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
//
// NRWindow.m
// NRTouchPoints
//
// Created by Natan Rolnik on 06/12/13.
// Copyright (c) 2013 Natan Rolnik. All rights reserved.
//
#import "NRWindow.h"
#import "UITouch+NRTouch.h"
@implementation NRWindow
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self initDefaults];
}
return self;
}
- (id)initWithCoder:(NSCoder *)coder
{
if (self = [super initWithCoder:coder]) {
[self initDefaults];
}
return self;
}
- (void)initDefaults
{
[self setTouchPointsEnabled:YES];
}
- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
if (self.touchPointsEnabled && event.type == UIEventTypeTouches)
{
for (UITouch *touch in [event allTouches])
{
if (touch.phase == UITouchPhaseBegan)
{
UIImageView *imageView = [[UIImageView alloc] initWithImage:[self imageForTouch]];
imageView.contentMode = UIViewContentModeRedraw;
touch.touchRepresentationView = imageView;
CGPoint point = [touch locationInView:self];
imageView.frame = CGRectMake(point.x - 20, point.y - 20, 40, 40);
[self addSubview:imageView];
}
else if (touch.phase == UITouchPhaseCancelled || touch.phase == UITouchPhaseEnded)
{
[touch.touchRepresentationView removeFromSuperview];
}
else if (touch.phase == UITouchPhaseMoved)
{
CGPoint point = [touch locationInView:self];
touch.touchRepresentationView.frame = CGRectMake(point.x - 20, point.y - 20, 40, 40);
}
}
}
}
-(UIImage *)imageForTouch
{
UIImage *imageForTouch = self.touchRepresentationCustomImage ? self.touchRepresentationCustomImage : [UIImage imageNamed:@"NRTouchImage"];
return imageForTouch;
}
@end