-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUIView+Extra.m
42 lines (35 loc) · 1.11 KB
/
UIView+Extra.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
//
// UIView+Extra.m
// ABTestPrototype
//
// Created by Manuel Meyer on 18.05.15.
// Copyright (c) 2015 Manuel Meyer. All rights reserved.
//
#import "UIView+Extra.h"
@implementation UIView (Extra)
- (UIView *)findTopMostViewForPoint:(CGPoint)point
{
for(NSInteger i = self.subviews.count - 1; i >= 0; --i)
{
UIView *subview = [self.subviews objectAtIndex:i];
if(!subview.hidden && CGRectContainsPoint(subview.frame, point))
{
CGPoint pointConverted = [self convertPoint:point toView:subview];
return [subview findTopMostViewForPoint:pointConverted];
}
}
return self;
}
- (BOOL)isTopmostViewInWindow
{
if(self.window == nil)
{
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;
}
@end