gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 10:07:12 26 4
gpt4 key购买 nike

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

我看到的是 -(UIStatusBarStyle)preferredStatusBarStyle 在 PRESENTING ViewController 上被调用(实际上是几次),而从未在新呈现的 上被调用 View Controller 。如果我删除自定义动画,状态栏的所有内容都会按我预期的方式工作。

我需要在我的 animateTransition 函数中做一些特别的事情来更新 Root View Controller 或其他什么吗?我尝试使用 [UIApplication sharedApplication] setStatusBarStyle 手动设置 statusBar,但它不起作用(我想是因为我使用的是基于 ios 7 View Controller 的状态栏样式)。

这是我的 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];
}];
}

非常感谢任何指点!

最佳答案

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

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

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

有一些 more information here .希望对您有所帮助!

关于ios - 如何将 StatusBar 样式更新为自定义转换的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23329498/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com