-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPTutorialInvisibleProxyView.m
More file actions
executable file
·85 lines (70 loc) · 3.03 KB
/
CPTutorialInvisibleProxyView.m
File metadata and controls
executable file
·85 lines (70 loc) · 3.03 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
//
// CPTutorialInvisibleProxyView.m
//
// Created by Can Poyrazoğlu on 29.11.14.
//
#import "CPTutorialInvisibleProxyView.h"
@implementation CPTutorialInvisibleProxyView{
CGRect lastFrame;
}
-(void)drawRect:(CGRect)rect{
//empty implementation. we shouldn't draw.
CGRect globalFrame = [self.superview.superview convertRect:self.superview.frame toView:[[self.delegate tutorialView] superview]];
if([self.delegate respondsToSelector:@selector(attachedViewFrameDidChange:)]){
[self.delegate attachedViewFrameDidChange:globalFrame];
}
}
-(void)setOpaque:(BOOL)opaque{
[super setOpaque:NO];
}
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
[super setOpaque:NO];
[super setUserInteractionEnabled:NO];
return self;
}
-(void)setUserInteractionEnabled:(BOOL)userInteractionEnabled{
if(userInteractionEnabled){
return;
}else{
[super setUserInteractionEnabled:userInteractionEnabled];
}
}
+(instancetype)proxyView{
CPTutorialInvisibleProxyView *view = [[CPTutorialInvisibleProxyView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
view.translatesAutoresizingMaskIntoConstraints = NO;
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view.contentMode = UIViewContentModeRedraw;
//immediately calling sequentially results in incorrect frame for some reason. this works though. yeah, a bit ugly code but it works nice. just don't open Pandora's "black" box :)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(DBL_EPSILON * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
CGRect globalFrame = [view.superview.superview convertRect:view.superview.frame toView:[[view.delegate tutorialView] superview]];
if([view.delegate respondsToSelector:@selector(attachedViewFrameDidChange:)]){
[view.delegate attachedViewFrameDidChange:globalFrame];
}
});
return view;
}
-(void)didMoveToSuperview{
CGRect globalFrame = [self.superview.superview convertRect:self.superview.frame toView:[[self.delegate tutorialView] superview]];
[self.superview sendSubviewToBack:self];
if([self.delegate respondsToSelector:@selector(attachedViewFrameDidChange:)]){
[self.delegate attachedViewFrameDidChange:globalFrame];
}
}
-(void)didMoveToWindow{
[self.delegate setHidden:!self.window];
CGRect globalFrame = [self.superview.superview convertRect:self.superview.frame toView:[[self.delegate tutorialView] superview]];
if([self.delegate respondsToSelector:@selector(attachedViewFrameDidChange:)]){
[self.delegate attachedViewFrameDidChange:globalFrame];
}
}
-(void)setFrame:(CGRect)frame{
[super setFrame:frame];
if(self.superview){
CGRect globalFrame = [self.superview.superview convertRect:self.superview.frame toView:[self.delegate tutorialView]];
if([self.delegate respondsToSelector:@selector(attachedViewFrameDidChange:)]){
[self.delegate attachedViewFrameDidChange:globalFrame];
}
}
}
@end