我怎样才能解决隐藏底部边框当我用iOS 6 SDK推动怪异?

我遇到了这个OpenRadar问题中描述的相同的问题。 如上所述:

简介:UIViewController的hidesBottomBarWhenPushed属性不能像使用iOS 6 SDK构build的应用程序那样工作(不是适用于iOS 7的beta SDK)。 隐藏底部栏(例如标签栏)时,animation很奇怪。

重现步骤:

  1. 使用Xcode 4中的TabBar模板创build一个新项目。将一个UINavigationController添加到FirstViewController。 在FirstViewController上添加一个button,并将其操作设置为推送一个新的视图控制器。 (请看附带的示例代码)

  2. 在iOS 7 beta 5设备上运行演示。

  3. 按下button,从UINavigationController返回,注意animation视图转换。

预期的结果:animation的工作原理与iOS 6设备完全相同。

实际结果:animation看起来很奇怪。 FirstViewController从底部向下滑动。

示例代码: http : //cl.ly/QgZZ

使用iOS 6 SDK进行构build时,有什么方法可以解决或解决这个问题吗?

这个问题肯定存在。 我做了一些调查,发现是什么原因造成的。 当使用UINavigationController推送视图控制器时,您将视图控制器的视图包含在UIViewControllerWrapperViewUIViewControllerWrapperView是由UINavigationControllerpipe理的私有Apple视图。 当过渡animation即将发生,并且hidesBottomBarWhenPushed设置为YES时,此UIViewControllerWrapperView被animation的Y轴的position错误,所以解决scheme只是覆盖此行为并给出正确的animation值。 代码如下:

 //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 } 

在我的情况下,我有TabBarViewControllerUINavigationController在每个标签和面临类似的问题。 我用了,

 nextScreen.hidesBottomBarWhenPushed = true pushViewToCentralNavigationController(nextScreen) 

当nextScreen是UITableViewController子类和应用的自动布局时,它工作正常。 但是,当nextScreenUIViewController时它不能正常工作。 我发现它取决于nextScreen自动布局约束。

所以我只是用这个代码更新了我的当前屏幕 –

 override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) self.tabBarController?.tabBar.hidden = true } 

通过这种方式,你可以达到预期的结果,但不是实现它的好方法。

希望能帮助到你。