如何将StatusBar样式更新为自定义转换的一部分

Car*_*een 15 iphone objective-c ios ios7

我正在使用iOS 7 UIviewControllerAnimatedTransitioning协议来呈现ViewController带有自定义动画的模态.动画工作正常,但是,我希望新呈现的ViewController状态栏样式与呈现VC不同.

我所看到的是在演讲中-(UIStatusBarStyle)preferredStatusBarStyle被召唤ViewController(实际上是好几次)而从未出现过ViewController.如果我删除自定义动画,状态栏的所有内容都按照我的预期运行.

在我的animateTransition函数中是否需要做一些特殊的事情来更新根视图控制器?我已经尝试手动设置statusBar [UIApplication sharedApplication] setStatusBarStyle但它不起作用(我想因为我使用的是基于ios 7视图控制器的状态栏样式).

这是我的animateTransition代码:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UICollectionViewCell *activeCell;
    if ([self.collectionView.visibleCells containsObject:self.cellForActiveIdeaVC]) {
        activeCell = self.cellForActiveIdeaVC;
    }

    UIView *container = transitionContext.containerView;
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *fromView = fromVC.view;
    UIView *toView = toVC.view;

    CGRect beginFrame;
    if (activeCell) {
        beginFrame = [container convertRect:activeCell.bounds fromView:activeCell];
    } else {
        beginFrame = CGRectMake(container.width / 2, container.height / 2, 0, 0);
    }

    CGRect endFrame = [transitionContext initialFrameForViewController:fromVC];

    UIView *move = nil;
    if (toVC.isBeingPresented) {
        toView.frame = endFrame;
        move = [toView snapshotViewAfterScreenUpdates:YES];
        move.frame = beginFrame;
    } else {
        if (activeCell) {
            move = [activeCell snapshotViewAfterScreenUpdates:YES];
        } else {
            move = [fromView snapshotViewAfterScreenUpdates:YES];
        }
        move.frame = fromView.frame;
        [fromView removeFromSuperview];
    }
    [container addSubview:move];

    [UIView animateWithDuration:.5
                          delay:0
         usingSpringWithDamping:700
          initialSpringVelocity:15
                        options:0
                     animations:^{
                         move.frame = toVC.isBeingPresented ?  endFrame : beginFrame;
                     }
                     completion:^(BOOL finished) {
                         [move removeFromSuperview];

                         if (toVC.isBeingPresented) {
                             toView.frame = endFrame;
                             [container addSubview:toView];
                         } else {
                             if (self.cellForActiveIdeaVC) {
                                 self.cellForActiveIdeaVC = nil;
                             }
                         }

                         [transitionContext completeTransition:YES];
                     }];
}
Run Code Online (Sandbox Code Playgroud)

任何指针都非常感谢!

Riz*_*tar 30

使用iOS 7自定义过渡,可以呈现不是全屏的视图控制器,因此不会影响状态栏外观.您必须明确告诉iOS,您的自定义显示的视图控制器实际上将控制状态栏的外观.

UIViewController *controllerToPresent = [...]
controllerToPresent.modalPresentationStyle = UIModalPresentationStyleCustom;
controllerToPresent.modalPresentationCapturesStatusBarAppearance = YES;

[self presentViewController:controllerToPresent animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

这里有更多信息.希望有所帮助!

  • 我知道是这样的,我只是找不到那个设置。非常感谢! (2认同)