ios滑动状态栏,带SWRevealViewController

ios滑动状态栏,带SWRevealViewController,ios,objective-c,Ios,Objective C,这是一个相当具体的问题,所以我不期望有太多的回答,但值得一试。我正在为我的应用程序使用,我想知道是否有人在使用SWRevealViewController时有幸实现了一个bar。我运气不错,但在提出新观点时遇到了问题 如果是这样的话,您是否介意分享一下您是如何做到这一点的?我认为您可以使用RevealControllerdelegate方法来设置动画或更新其x位置。大概是这样的: 手动滑动时更新状态栏: - (void)revealController:(SWRevealViewControll

这是一个相当具体的问题,所以我不期望有太多的回答,但值得一试。我正在为我的应用程序使用,我想知道是否有人在使用SWRevealViewController时有幸实现了一个bar。我运气不错,但在提出新观点时遇到了问题


如果是这样的话,您是否介意分享一下您是如何做到这一点的?

我认为您可以使用
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;
    }];

  }
}

上述解决方案并不完整,并不适用于所有情况。这里是完整而健壮的解决方案

1。定义局部布尔值以在菜单打开时设置为真,在菜单关闭时设置为假<代码>@property(非原子,读写)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;
    }
}