Skip to content

Commit 28bb65a

Browse files
committed
separate UIWindow category
1 parent b85562c commit 28bb65a

4 files changed

Lines changed: 73 additions & 53 deletions

File tree

SIAlertView/SIAlertView.m

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "SIAlertView.h"
10+
#import "UIWindow+SIUtils.h"
1011
#import <QuartzCore/QuartzCore.h>
1112

1213
NSString *const SIAlertViewWillShowNotification = @"SIAlertViewWillShowNotification";
@@ -36,59 +37,6 @@
3637
static SIAlertBackgroundWindow *__si_alert_background_window;
3738
static SIAlertView *__si_alert_current_view;
3839

39-
@interface UIWindow (SIAlert_Utils)
40-
41-
- (UIViewController *)currentViewController;
42-
43-
@end
44-
45-
@implementation UIWindow (SIAlert_Utils)
46-
47-
- (UIViewController *)currentViewController
48-
{
49-
UIViewController *viewController = self.rootViewController;
50-
while (viewController.presentedViewController) {
51-
viewController = viewController.presentedViewController;
52-
}
53-
return viewController;
54-
}
55-
56-
@end
57-
58-
#ifdef __IPHONE_7_0
59-
@interface UIWindow (SIAlert_StatusBarUtils)
60-
61-
- (UIViewController *)viewControllerForStatusBarStyle;
62-
- (UIViewController *)viewControllerForStatusBarHidden;
63-
64-
@end
65-
66-
@implementation UIWindow (SIAlert_StatusBarUtils)
67-
68-
- (UIViewController *)viewControllerForStatusBarStyle
69-
{
70-
UIViewController *currentViewController = [self currentViewController];
71-
72-
while ([currentViewController childViewControllerForStatusBarStyle]) {
73-
currentViewController = [currentViewController childViewControllerForStatusBarStyle];
74-
}
75-
return currentViewController;
76-
}
77-
78-
- (UIViewController *)viewControllerForStatusBarHidden
79-
{
80-
UIViewController *currentViewController = [self currentViewController];
81-
82-
while ([currentViewController childViewControllerForStatusBarHidden]) {
83-
currentViewController = [currentViewController childViewControllerForStatusBarHidden];
84-
}
85-
return currentViewController;
86-
}
87-
88-
@end
89-
#endif
90-
91-
9240
@interface SIAlertView ()
9341

9442
@property (nonatomic, strong) NSMutableArray *items;

SIAlertView/UIWindow+SIUtils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// UIWindow+SIUtils.h
3+
// SIAlertViewExample
4+
//
5+
// Created by Kevin Cao on 13-11-1.
6+
// Copyright (c) 2013年 Sumi Interactive. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface UIWindow (SIUtils)
12+
13+
- (UIViewController *)currentViewController;
14+
15+
#ifdef __IPHONE_7_0
16+
- (UIViewController *)viewControllerForStatusBarStyle;
17+
- (UIViewController *)viewControllerForStatusBarHidden;
18+
#endif
19+
20+
@end

SIAlertView/UIWindow+SIUtils.m

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// UIWindow+SIUtils.m
3+
// SIAlertViewExample
4+
//
5+
// Created by Kevin Cao on 13-11-1.
6+
// Copyright (c) 2013年 Sumi Interactive. All rights reserved.
7+
//
8+
9+
#import "UIWindow+SIUtils.h"
10+
11+
@implementation UIWindow (SIUtils)
12+
13+
- (UIViewController *)currentViewController
14+
{
15+
UIViewController *viewController = self.rootViewController;
16+
while (viewController.presentedViewController) {
17+
viewController = viewController.presentedViewController;
18+
}
19+
return viewController;
20+
}
21+
22+
#ifdef __IPHONE_7_0
23+
24+
- (UIViewController *)viewControllerForStatusBarStyle
25+
{
26+
UIViewController *currentViewController = [self currentViewController];
27+
28+
while ([currentViewController childViewControllerForStatusBarStyle]) {
29+
currentViewController = [currentViewController childViewControllerForStatusBarStyle];
30+
}
31+
return currentViewController;
32+
}
33+
34+
- (UIViewController *)viewControllerForStatusBarHidden
35+
{
36+
UIViewController *currentViewController = [self currentViewController];
37+
38+
while ([currentViewController childViewControllerForStatusBarHidden]) {
39+
currentViewController = [currentViewController childViewControllerForStatusBarHidden];
40+
}
41+
return currentViewController;
42+
}
43+
44+
#endif
45+
46+
@end

SIAlertViewExample/SIAlertViewExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
7E23C6A31732776100784CF1 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 7E23C6A21732776100784CF1 /* [email protected] */; };
3939
7E23C6A8173277EA00784CF1 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 7E23C6A7173277EA00784CF1 /* Icon-72.png */; };
4040
7E23C6AA173277EE00784CF1 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 7E23C6A9173277EE00784CF1 /* [email protected] */; };
41+
7EEECA69182350B1001FEDF5 /* UIWindow+SIUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EEECA68182350B1001FEDF5 /* UIWindow+SIUtils.m */; };
4142
/* End PBXBuildFile section */
4243

4344
/* Begin PBXFileReference section */
@@ -78,6 +79,8 @@
7879
7E23C6A21732776100784CF1 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
7980
7E23C6A7173277EA00784CF1 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72.png"; sourceTree = "<group>"; };
8081
7E23C6A9173277EE00784CF1 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
82+
7EEECA67182350B1001FEDF5 /* UIWindow+SIUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIWindow+SIUtils.h"; sourceTree = "<group>"; };
83+
7EEECA68182350B1001FEDF5 /* UIWindow+SIUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIWindow+SIUtils.m"; sourceTree = "<group>"; };
8184
/* End PBXFileReference section */
8285

8386
/* Begin PBXFrameworksBuildPhase section */
@@ -175,6 +178,8 @@
175178
7E23C69917325EBD00784CF1 /* SIAlertView.bundle */,
176179
7E23C69A17325EBD00784CF1 /* SIAlertView.h */,
177180
7E23C69B17325EBD00784CF1 /* SIAlertView.m */,
181+
7EEECA67182350B1001FEDF5 /* UIWindow+SIUtils.h */,
182+
7EEECA68182350B1001FEDF5 /* UIWindow+SIUtils.m */,
178183
);
179184
name = SIAlertView;
180185
path = ../SIAlertView;
@@ -300,6 +305,7 @@
300305
7E23C68317325EAA00784CF1 /* AppDelegate.m in Sources */,
301306
7E23C69217325EAB00784CF1 /* ViewController.m in Sources */,
302307
7E23C69D17325EBD00784CF1 /* SIAlertView.m in Sources */,
308+
7EEECA69182350B1001FEDF5 /* UIWindow+SIUtils.m in Sources */,
303309
);
304310
runOnlyForDeploymentPostprocessing = 0;
305311
};

0 commit comments

Comments
 (0)