2014-01-19 41 views
4

这是一个相当具体的问题,所以我不期待吨响应,但它是值得一试。我正在使用SWRevealViewController作为我的应用程序,我想知道是否有人在使用SWRevealViewController时有任何实施sliding status栏的运气。我有过一些运气,但在推出新视图时遇到了问题。ios幻灯片状态栏与SWRevealViewController

如果是这样,你会介意分享你是如何做到的?

+0

你有没有想过这个?我正在努力解决同样的问题 – Thomas

回答

0

上述解决方案是不完整的,对所有的情况下无法正常工作。这里是完整而强大的解决方案。

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

    } 
}