我正在尝试找到一种干净的方式来处理UIPageViewController和状态栏。我注意到Snapchat在滑动到没有显示状态栏的新页面时,通过在状态栏上滑动viewcontroller来完美地完成它。它看起来像这样......
snapchat statusbar uipageviewcontroller http://i62.tinypic.com/htcrj5.png
有谁知道这是怎么做的?我能想到的唯一方法是使用不同的UIWindow,但是如何实现具有多个UIWindows的UIPageViewController?如果这就是正在做的事情。否则如何实现这种效果?
答案 0 :(得分:0)
基本上创建一个UIViewController,把UIPageViewController放在里面。使UIVC的大小与iphone屏幕的大小相同。然后将appdelegate.window.rootviewcontroller设置为UIViewControllers
以下是此任务的一个很好的示例回购:https://github.com/goktugyil/EZSwipeController
答案 1 :(得分:0)
好的,所以这实际上是使用一些聪明的技巧完成的。
基本上它并没有实际移动状态栏,而是移动状态栏的图像。
免责声明:我执行此实施工具,因此我不保证它是否可以开箱即用
从iOS7开始,您可以使用
拍摄照片UIView *screen = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];
我看到here提供了更多有用的信息。但基本上状态栏会从图片中裁剪下来,并添加到UIWindow
windowLevel
以上UIWindowStatusLevelBar
,这将掩盖真实的状态栏。类似的东西:
UIWindow *statusBarWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
statusBarWindow.windowLevel = UIWindowLevelStatusBar;
statusBarWindow.hidden = NO; // fun fact you don't have to add a UIWindow to anything, just setting hidden = NO should display it
statusBarWindow.backgroundColor = [UIColor clearColor]; // I have no idea if this is necessary but since it's now visible you def don't want it to have a color
...
// The view that will hold the screen shot
UIView *statusBarView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
statusBarView.clipsToBounds = YES;
// Now we add the screen shot we took to this status bar view
[statusBarView addSubview:screen]; // screen is the UIView from previous code block
// Now add this statusBarView with the image to the window we created
[statusBarWindow addSubview:statusBarView];
现在其余部分真的取决于你的实现是什么样的,但是从这里你真的只需要处理移动视图的平移,或任何导致新视图进入侧面的动作:
// you're going to want to hide the status bar when this action starts so that your new window is visible
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
// then inside whatever method is handling the sliding you're going to adjust the frame of the statusBarView
// this can be done explicitly by setting a new frame, or animating its x position, or whatever
// if you're doing it explicitly something like:
CGFloat offset = self.viewThatIsScrolling.contentOffset.x; // may be negative depending on direction that is being swiped
statusBarView.frame = CGRectMake(offset, 0, self.statusBarView.frame.width, 20.0f);
// or maybe even
statusBarView.transform = CGAffineTransformMakeTranslation(offset -previousOffsetAmount, 0); // you only want it to move over by whatever new amount so it can match up, this will have to be tracked somehow if you go this route
...
// and finally once the 'sliding' is done don't forget to remove the screenshot and unhide the status bar
// (can check by looking at the offset value from earlier or as a callback after animation, or whatever)
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[statusBarView removeFromSuperview];
statusBarView = nil;
另请注意,这不会处理方向更改或任何内容(固定框架可能导致其无法工作)。你可以使用autoResizingMask
或其他东西