如何在自定义过渡中更新StatusBar样式

卡尔·舒格林

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

我看到的是-(UIStatusBarStyle)preferredStatusBarStyle在PRESENTING 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];
                     }];
}

任何指针,不胜感激!

里兹旺·萨塔尔(Rizwan Sattar)

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

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

[self presentViewController:controllerToPresent animated:YES completion:nil];

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在 React 中设置自定义 css 样式?

如何在Angular CLI中包含自定义样式

如何在图表中自定义样式数据标签?

如何在gnuplot中创建自定义填充样式?

PageViewController自定义过渡样式

如何在自定义tableViewController中过渡到另一个viewController?

如何在使用AnyView制作的自定义NavigationItem之间的过渡子中添加动画?

如何在 Wordpress 中为自定义帖子类型加载自定义样式表?

如何在 JavaFX 中的 ListView 中设置自定义控件的样式

如何在ejs中的HTML元素中添加自定义样式?

如何在Reactstrap输入上应用自定义样式?

如何在标签视图上应用自定义样式

如何在开关上设置自定义样式

如何在Flutter中使用自定义字体样式?

如何在TreeView中为工具提示提供MaxWidth(或自定义样式)

如何在样式化组件中向主题提供者添加自定义字体?

如何在android中为样式指定商品的自定义包装名称?

如何在自定义ItemsControl的ItemsPresenter中设置项目样式?

如何在我的SharePoint 2013博客中添加自定义段落样式?

如何在自定义Android XML中手动查找“ @string / ...”样式引用

Vuetify-如何在<v-select>中自定义选项的样式?

如何在小吃栏中自定义动作按钮的样式

如何在JavaFX CSS中创建自定义边框样式?

如何在Android中设置自定义搜索建议列表的样式

如何在clang格式的函数参数包装和对齐中施加自己的自定义样式?

如何在 TCPDF 中添加带有样式的自定义页脚

如何在Angular中实现PrimeNG样式类以自定义轮播组件?

如何在b-col(bootstrap-vue)元素中绑定自定义样式?

如何在Android中设置自定义不同的字体样式