这是一个相当具体的问题,所以我不期待大量的回应,但值得一试。我正在使用SWRevealViewController作为我的应用程序,我想知道是否有人在使用SWRevealViewController时实现sliding status栏有任何好运。我有一些运气,但在推新观点时遇到了问题。
如果是这样,你介意分享你是如何做到这一点的吗?
答案 0 :(得分: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;
}];
}
}
答案 1 :(得分: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;
}
}