Skip to content

Commit e579019

Browse files
committed
- Overriding layoutSubviews and resizing left and right menus accordingly
1 parent 819f691 commit e579019

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

SlideMenu/Source/SlideNavigationController.m

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,29 @@ + (SlideNavigationController *)sharedInstance
5050
return singletonInstance;
5151
}
5252

53-
- (void)awakeFromNib
53+
- (id)init
5454
{
55-
[self setup];
55+
if (self = [super init])
56+
{
57+
[self setup];
58+
}
59+
60+
return self;
5661
}
5762

58-
- (id)initWithRootViewController:(UIViewController *)rootViewController
63+
- (id)initWithCoder:(NSCoder *)aDecoder
5964
{
60-
if (self = [super initWithRootViewController:rootViewController])
65+
if (self = [super initWithCoder:aDecoder])
6166
{
6267
[self setup];
6368
}
6469

6570
return self;
6671
}
6772

68-
- (id)init
73+
- (id)initWithRootViewController:(UIViewController *)rootViewController
6974
{
70-
if (self = [super init])
75+
if (self = [super initWithRootViewController:rootViewController])
7176
{
7277
[self setup];
7378
}
@@ -88,19 +93,22 @@ - (void)setup
8893
self.view.layer.shouldRasterize = YES;
8994
self.view.layer.rasterizationScale = [UIScreen mainScreen].scale;
9095

91-
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidChangeStatusBarFrameNotification
92-
object:nil
93-
queue:nil
94-
usingBlock:^(NSNotification *note){
95-
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
96-
// Do more resizing on menus
97-
[self.leftMenu.view setTransform:[self transformForOrientation:orientation]];
98-
[self.righMenu.view setTransform:[self transformForOrientation:orientation]];
99-
}];
100-
10196
[self setEnableSwipeGesture:YES];
10297
}
10398

99+
- (void)viewWillLayoutSubviews
100+
{
101+
[super viewWillLayoutSubviews];
102+
103+
CGAffineTransform transform = self.view.transform;
104+
self.leftMenu.view.transform = transform;
105+
self.righMenu.view.transform = transform;
106+
107+
CGRect rect = self.view.frame;
108+
self.leftMenu.view.frame = rect;
109+
self.righMenu.view.frame = rect;
110+
}
111+
104112
#pragma mark - Public Methods -
105113

106114
- (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion
@@ -210,7 +218,7 @@ - (UIBarButtonItem *)barButtonItemForMenu:(Menu)menu
210218

211219
- (BOOL)isMenuOpen
212220
{
213-
if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation))
221+
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
214222
{
215223
return (self.view.frame.origin.y == 0) ? NO : YES;
216224
}
@@ -301,29 +309,10 @@ - (void)closeMenuWithCompletion:(void (^)())completion
301309
[self closeMenuWithDuration:MENU_SLIDE_ANIMATION_DURATION andCompletion:completion];
302310
}
303311

304-
- (CGAffineTransform)transformForOrientation:(UIInterfaceOrientation)orientation
305-
{
306-
switch (orientation)
307-
{
308-
case UIInterfaceOrientationLandscapeLeft:
309-
return CGAffineTransformMakeRotation(-DegreesToRadians(90));
310-
311-
case UIInterfaceOrientationLandscapeRight:
312-
return CGAffineTransformMakeRotation(DegreesToRadians(90));
313-
314-
case UIInterfaceOrientationPortraitUpsideDown:
315-
return CGAffineTransformMakeRotation(DegreesToRadians(180));
316-
317-
case UIInterfaceOrientationPortrait:
318-
default:
319-
return CGAffineTransformMakeRotation(DegreesToRadians(0));
320-
}
321-
}
322-
323312
- (void)moveHorizontallyToLocation:(CGFloat)location
324313
{
325314
CGRect rect = self.view.frame;
326-
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;
315+
UIInterfaceOrientation orientation = self.interfaceOrientation;
327316

328317
if (UIInterfaceOrientationIsLandscape(orientation))
329318
{
@@ -342,7 +331,7 @@ - (void)moveHorizontallyToLocation:(CGFloat)location
342331
- (CGFloat)horizontalLocation
343332
{
344333
CGRect rect = self.view.frame;
345-
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;
334+
UIInterfaceOrientation orientation = self.interfaceOrientation;
346335

347336
if (UIInterfaceOrientationIsLandscape(orientation))
348337
{

0 commit comments

Comments
 (0)