【问题标题】:Slide UIPageViewController page over the status bar在状态栏上滑动 UIPageViewController 页面
【发布时间】:2014-08-25 21:22:41
【问题描述】:

我正在尝试寻找一种干净的方式来处理 UIPageViewController 和状态栏。我注意到当您滑动到不显示状态栏的新页面时,Snapchat 通过将视图控制器滑过状态栏来完美地做到这一点。好像是这样的……

有人知道这是怎么做到的吗?我能想到的唯一方法是使用不同的 UIWindow,但是如何实现具有多个 UIWindows 的 UIPageViewController?如果这就是正在做的事情。不然怎么达到这个效果?

【问题讨论】:

  • 我不认为他们正在使用 UIPageViewController 很可能他们正在呈现一个新的 UIViewController 并且他们正在隐藏状态栏。我会使用 UIKitDynamics developer.apple.com/library/ios/samplecode/DynamicsCatalog/… 来做到这一点,并且只需在 containerViewController 上呈现一个 viewController 类似于 UIPageViewController 的想法,但你不必处理代表
  • 我认为他们必须使用不同的 UIWindow。据我所知,如果你隐藏状态栏,只要新视图接管它就会消失。它不会在新视图下滑动。

标签: ios ios7 uipageviewcontroller ios7-statusbar snapchat


【解决方案1】:

基本上创建一个 UIViewController,把 UIPageViewController 放在里面。使 UIVC 的大小成为 iphone 屏幕的大小。然后将 appdelegate.window.rootviewcontroller 设置为您的 UIViewControllers

这里是这个任务的一个很好的示例代码库:https://github.com/goktugyil/EZSwipeController

【讨论】:

    【解决方案2】:

    好的,这实际上是使用一些巧妙的技巧完成的。

    基本上它实际上并不是在移动状态栏,而是在移动状态栏的图像。

    免责声明:我 YOLO 完成了这个实现,所以我不保证它是否能开箱即用

    从iOS7开始你可以使用拍照

    UIView *screen = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];
    

    我看到了更多有用的信息here。但基本上状态栏是从图片中裁剪出来的,并添加到UIWindowwindowLevel 上方的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 或其他东西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 2015-10-06
      • 2014-01-29
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多