问题描述
我遇到了中描述的相同问题。如上所述:
I ran into the same problem described in this OpenRadar issue. As stated there:
重现步骤:
-
使用Xcode中的TabBar模板创建一个新项目4.将UINavigationController添加到FirstViewController。在
FirstViewController上添加一个按钮,并设置其动作以推送新的视图控制器。
(请参阅附带的示例代码)
Create a new project with the TabBar template in Xcode 4. Add a UINavigationController to the FirstViewController. Add a button on the FirstViewController and set its action to push a new view controller. (please see the sample code attached)
在iOS 7 beta 5设备上运行演示。
Run the demo on an iOS 7 beta 5 device.
按下按钮,从UINavigationController返回,注意动画视图过渡。
Press the button, back from the UINavigationController, pay attention to the animated view transitions.
预期结果:动画与iOS 6
设备完全相同。
Expected Results: The animation works exactly the same as on an iOS 6 device.
实际结果:动画看起来很奇怪。 FirstViewController从底部向下滑动
。
Actual Results: The animation looks weird. The FirstViewController is sliding down from the bottom.
示例代码:
有什么方法可以修复或解决这个问题使用iOS 6 SDK?
Is there any way to fix or work around this when building with the iOS 6 SDK?
推荐答案
这个问题肯定存在。我做了一些调查,发现了导致它的原因。使用 UINavigationController
推送视图控制器时,您查看控制器的视图包含在 UIViewControllerWrapperView
中,这是私有Apple的视图管理通过 UINavigationController
。当转换动画即将发生并且 hidesBottomBarWhenPushed
设置为YES时,此 UIViewControllerWrapperView
正在设置错误的动画 position ,因此解决方案只是覆盖此行为并为动画提供正确的值。这是代码:
This issue definitely exists. I did some investigation and found out what's causing it. When pushing a view controller with UINavigationController
, you view controller's view is contained in a UIViewControllerWrapperView
, which a private Apple's view managed by the UINavigationController
. When the transition animation is about to occur and the hidesBottomBarWhenPushed
is set to YES, this UIViewControllerWrapperView
is being animated with wrong position
for the Y axis, so the solution is just to overwrite this behaviour and give correct values for the animation. Here's the code:
//Declare a property
@property (nonatomic, assign) BOOL shouldFixAnimation;
...
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
#ifndef __IPHONE_7_0 //If this constant is not defined then we probably build against lower SDK and we should do the fix
if (self.hidesBottomBarWhenPushed && [[[UIDevice currentDevice] systemVersion] floatValue] >= 7 && animated && self.navigationController) {
self.shouldFixAnimation = YES;
}
#endif
}
-(void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
#ifndef __IPHONE_7_0
if(self.shouldFixAnimation) {
self.shouldFixAnimation = NO;
CABasicAnimation *basic = (CABasicAnimation *)[self.view.superview.layer animationForKey:@"position"]; //The superview is this UIViewControllerWrapperView
//Just in case for future changes from Apple
if(!basic || ![basic isKindOfClass:[CABasicAnimation class]])
return;
if(![basic.fromValue isKindOfClass:[NSValue class]])
return;
CABasicAnimation *animation = [basic mutableCopy];
CGPoint point = [basic.fromValue CGPointValue];
point.y = self.view.superview.layer.position.y;
animation.fromValue = [NSValue valueWithCGPoint:point];
[self.view.superview.layer removeAnimationForKey:@"position"];
[self.view.superview.layer addAnimation:animation forKey:@"position"];
}
#endif
}
这篇关于我如何解决hidesBottomBarWhenPushed与iOS 6 SDK的行为奇怪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!