JLChen
2021-11-04 1443556e9ccb1a19ed8e6710c16c8adc4d4f4fb3
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
//
//  Copyright © 2016年 dahua. All rights reserved.
//
 
#import "UIApplication+LeChange.h"
 
@implementation UIApplication (LeChange)
 
/// 判断App是否为横屏
///
/// - Returns: Bool
+ (BOOL)lc_isAppLandscape
{
    UIInterfaceOrientation orientation = [self sharedApplication].statusBarOrientation;
    return UIInterfaceOrientationIsLandscape(orientation);
}
 
/// 判断App是否为竖屏
///
/// - Returns: Bool
+ (BOOL)lc_isAppPortrait
{
    UIInterfaceOrientation orientation = [self sharedApplication].statusBarOrientation;
    return UIInterfaceOrientationIsPortrait(orientation);
}
 
/// App当前方向
///
/// - Returns: UIInterfaceOrientation
+ (UIInterfaceOrientation) lc_appOrientation
{
    return [self sharedApplication].statusBarOrientation;
}
 
+ (UIWindow *)lc_appWindow
{
    UIWindow *keyWindow;
    if([UIApplication sharedApplication].keyWindow == nil || [UIApplication sharedApplication].keyWindow.hidden)
    {
        NSLog(@"MMSheetView-show-keyWindow nil or hidden");
        int maxState = -1;
        UIWindow* keyWind = nil;
        for (UIWindow* wind in [UIApplication sharedApplication].windows )
        {
            if (wind.hidden == NO)
            {
                if (wind.windowLevel > maxState)
                {
                    keyWind = wind;
                    maxState = wind.windowLevel;
                }
            }
        }
        
        keyWindow = keyWind;
        //一般不会进这个地方
        if (keyWindow == nil)
        {
            keyWindow = [[UIApplication sharedApplication].windows lastObject];
        }
    }
    else
    {
        keyWindow = [UIApplication sharedApplication].delegate.window;
    }
    
    return keyWindow;
}
@end