Ios slide status bar using SWRevealViewController

This is a pretty specific question, so I don't expect a ton of answers, but it's worth it. I am using SWRevealViewController for my application and I am wondering if anyone will be able to successfully implement the rolling status when using SWRevealViewController. I had luck, but there were problems when clicking new views.

If so, could you share how you could do this?

+4
source share
2 answers

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;
    }
}
0

, RevealControllerdelegate x. - :

:

- (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress overProgress:(CGFloat)overProgress {
    NSLog(@"6progress: %f", progress);

    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 (!isDrawerOpen) {

    [UIView animateWithDuration:0.25 animations:^{
        statusBarView.transform = CGAffineTransformMakeTranslation(self.revealViewController.rearViewRevealWidth, 0.0f);
    } completion:^(BOOL finished) {
        isDrawerOpen = true;
    }];

} else {

    [UIView animateWithDuration:0.25 animations:^{
        statusBarView.transform = CGAffineTransformMakeTranslation(0, 0.0f);
    } completion:^(BOOL finished) {
        isDrawerOpen = false;
    }];

  }
}
0

All Articles