-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIView+ChameleonPrivate.m
executable file
·46 lines (32 loc) · 1.26 KB
/
UIView+ChameleonPrivate.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
//
// UIView+ChameleonPrivate.m
// Chameleon
//
// Created by Vicc Alexander on 6/4/15.
// Copyright (c) 2015 Vicc Alexander. All rights reserved.
//
#import "UIView+ChameleonPrivate.h"
@implementation UIView (ChameleonPrivate)
- (BOOL)isTopViewInWindow {
if (!self.window) {
return NO;
}
CGPoint centerPointInSelf = CGPointMake(CGRectGetMidX(self.bounds),
CGRectGetMidY(self.bounds));
CGPoint centerPointOfSelfInWindow = [self convertPoint:centerPointInSelf
toView:self.window];
UIView *view = [self.window findTopMostViewForPoint:centerPointOfSelfInWindow];
BOOL isTopMost = view == self || [view isDescendantOfView:self];
return isTopMost;
}
- (UIView *)findTopMostViewForPoint:(CGPoint)point {
for (int i = (int)self.subviews.count - 1; i >= 0; i--) {
UIView *subview = self.subviews[i];
if (!subview.hidden && CGRectContainsPoint(subview.frame, point) && subview.alpha > 0.01) {
CGPoint pointConverted = [self convertPoint:point toView:subview];
return [subview findTopMostViewForPoint:pointConverted];
}
}
return self;
}
@end