The above solution is not complete and does not work for all cases. Here is a complete and reliable solution.
1. , true, false, . @property (nonatomic, readwrite) BOOL isMenuOpen;. .
2. , .
-(void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position
{
switch (position) {
case FrontViewPositionLeftSideMostRemoved:
NSLog(@"RevealView: FrontViewPositionLeftSideMostRemoved");
break;
case FrontViewPositionLeftSideMost:
NSLog(@"RevealView: FrontViewPositionLeftSideMost");
break;
case FrontViewPositionLeftSide:
NSLog(@"RevealView: FrontViewPositionLeftSide");
break;
case FrontViewPositionLeft:
NSLog(@"RevealView: FrontViewPositionLeft");
isMenuOpen = false;
break;
case FrontViewPositionRight:
NSLog(@"RevealView: FrontViewPositionRight");
isMenuOpen = true;
break;
case FrontViewPositionRightMost:
NSLog(@"RevealView: FrontViewPositionRightMost");
break;
case FrontViewPositionRightMostRemoved:
NSLog(@"RevealView: FrontViewPositionRightMostRemoved");
break;
default:
break;
}
}
3. , , , , , .
#pragma mark - SWRevealViewControllerDelegate
- (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress overProgress:(CGFloat)overProgress {
UIView *statusBarView = [[UIApplication sharedApplication] valueForKey:[@[@"status", @"Bar"] componentsJoinedByString:@""]];
statusBarView.transform = CGAffineTransformMakeTranslation(progress * self.revealViewController.rearViewRevealWidth, 0.0f);
}
- (void) revealController:(SWRevealViewController *)revealController animateToPosition:(FrontViewPosition)position {
NSLog(@"animateToPosition: %ld", (long)position);
UIView *statusBarView = [[UIApplication sharedApplication] valueForKey:[@[@"status", @"Bar"] componentsJoinedByString:@""]];
if (position == FrontViewPositionRight) {
[UIView animateWithDuration:0.25 animations:^{
statusBarView.transform = CGAffineTransformMakeTranslation(self.revealViewController.rearViewRevealWidth, 0.0f);
} completion:^(BOOL finished) {
isMenuOpen = true;
}];
} else if (FrontViewPositionLeft) {
[UIView animateWithDuration:0.25 animations:^{
statusBarView.transform = CGAffineTransformMakeTranslation(0, 0.0f);
} completion:^(BOOL finished) {
isMenuOpen = false;
}];
}
}
4. . , , , , . viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
5. ( ).
- (void)deviceOrientationDidChange:(NSNotification *)notification
{
[self updateOrientationForStatusBar];
}
- (void)updateOrientationForStatusBar
{
switch ([UIDevice currentDevice].orientation)
{
case UIDeviceOrientationPortrait:
{
UIView *statusBarView = [[UIApplication sharedApplication] valueForKey:[@[@"status", @"Bar"] componentsJoinedByString:@""]];
if (isMenuOpen) {
statusBarView.transform = CGAffineTransformMakeTranslation(self.revealViewController.rearViewRevealWidth, 0.0f);
} else {
statusBarView.transform = CGAffineTransformMakeTranslation(0, 0.0f);
}
}
break;
case UIDeviceOrientationLandscapeLeft:
case UIDeviceOrientationLandscapeRight:
case UIDeviceOrientationPortraitUpsideDown:
case UIDeviceOrientationUnknown:
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationFaceDown:
break;
}
}