我使用的是 iOS 7UIviewControllerAnimatedTransitioning
呈现模式的协议ViewController
带有自定义动画。动画工作正常,但是我想要新呈现的ViewController
具有与当前 VC 不同的状态栏样式。
我看到的是-(UIStatusBarStyle)preferredStatusBarStyle
在 PRESENTING 上被叫去ViewController
(事实上有好几次)并且从来没有在新推出的ViewController
。如果我删除自定义动画,状态栏的所有内容都会按我的预期工作。
我需要在 animateTransition 函数中做一些特殊的事情来更新根视图控制器或其他东西吗?我尝试过手动设置状态栏[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];
}];
}
非常感谢任何指点!
使用 iOS 7 自定义转换,可以呈现非全屏的视图控制器,因此不会影响状态栏的外观。您必须明确告诉 iOS,您的自定义呈现视图控制器实际上将控制状态栏的外观。
UIViewController *controllerToPresent = [...]
controllerToPresent.modalPresentationStyle = UIModalPresentationStyleCustom;
controllerToPresent.modalPresentationCapturesStatusBarAppearance = YES;
[self presentViewController:controllerToPresent animated:YES completion:nil];
有一些更多信息请点击此处 http://lxcid.com/2013/11/29/status-bar-remains-unchange-when-view-controller-is-pushed-presented-modally/。希望有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)