我正在使用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];
}];
}
任何指针,不胜感激!
使用iOS 7自定义过渡,可以呈现不是全屏显示的视图控制器,因此不会影响状态栏的外观。您必须明确告诉iOS,您自定义显示的视图控制器实际上将控制状态栏的外观。
UIViewController *controllerToPresent = [...]
controllerToPresent.modalPresentationStyle = UIModalPresentationStyleCustom;
controllerToPresent.modalPresentationCapturesStatusBarAppearance = YES;
[self presentViewController:controllerToPresent animated:YES completion:nil];
这里有更多信息。希望对您有所帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句