Skip to content

Commit cfb81f9

Browse files
committed
better rotation support
fix Sumi-Interactive#46 fix Sumi-Interactive#50
1 parent f9ac687 commit cfb81f9

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

SIAlertView/SIAlertView.m

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@
3636
static SIAlertBackgroundWindow *__si_alert_background_window;
3737
static SIAlertView *__si_alert_current_view;
3838

39-
#ifdef __IPHONE_7_0
40-
@interface UIWindow (SIAlert_StatusBarUtils)
39+
@interface UIWindow (SIAlert_Utils)
4140

42-
- (UIViewController *)viewControllerForStatusBarStyle;
43-
- (UIViewController *)viewControllerForStatusBarHidden;
41+
- (UIViewController *)currentViewController;
4442

4543
@end
4644

47-
@implementation UIWindow (SIAlert_StatusBarUtils)
45+
@implementation UIWindow (SIAlert_Utils)
4846

4947
- (UIViewController *)currentViewController
5048
{
@@ -55,6 +53,18 @@ - (UIViewController *)currentViewController
5553
return viewController;
5654
}
5755

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+
5868
- (UIViewController *)viewControllerForStatusBarStyle
5969
{
6070
UIViewController *currentViewController = [self currentViewController];
@@ -223,16 +233,28 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte
223233

224234
- (NSUInteger)supportedInterfaceOrientations
225235
{
236+
UIViewController *viewController = [self.alertView.oldKeyWindow currentViewController];
237+
if (viewController) {
238+
return [viewController supportedInterfaceOrientations];
239+
}
226240
return UIInterfaceOrientationMaskAll;
227241
}
228242

229243
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
230244
{
245+
UIViewController *viewController = [self.alertView.oldKeyWindow currentViewController];
246+
if (viewController) {
247+
return [viewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
248+
}
231249
return YES;
232250
}
233251

234252
- (BOOL)shouldAutorotate
235253
{
254+
UIViewController *viewController = [self.alertView.oldKeyWindow currentViewController];
255+
if (viewController) {
256+
return [viewController shouldAutorotate];
257+
}
236258
return YES;
237259
}
238260

SIAlertViewExample/SIAlertViewExample/ViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "SIAlertView.h"
1111

1212
#define TEST_UIAPPEARANCE 1
13+
#define TEST_AUTO_ROTATE 0
1314

1415
@interface ViewController ()
1516

@@ -225,7 +226,11 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfa
225226

226227
- (BOOL)shouldAutorotate
227228
{
229+
#if TEST_AUTO_ROTATE
228230
return YES;
231+
#else
232+
return NO;
233+
#endif
229234
}
230235

231236
@end

0 commit comments

Comments
 (0)