我如何解决hidesBottomBarWhenPushed与iOS 6 SDK的行为奇怪?

lu *_*uan 0 uiviewcontroller ios ios7

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

简介:UIViewController的hidesBottomBarWhenPushed属性对于使用iOS 6 SDK构建的应用程序(不适用于iOS 7的beta SDK)无法正常工作.隐藏底栏(例如标签栏)时动画很奇怪.

重现步骤:

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

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

  3. 按下按钮,从UINavigationController返回,注意动画视图过渡.

预期结果:动画与iOS 6设备完全相同.

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

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

使用iOS 6 SDK构建时,有什么办法可以解决或解决这个问题吗?

gra*_*ver 6

这个问题肯定存在.我做了一些调查,发现了导致它的原因.当推动视图控制器时UINavigationController,您查看控制器的视图包含在UIViewControllerWrapperView一个私有Apple的视图中UINavigationController.当过渡动画即将发生并且hidesBottomBarWhenPushed设置为YES时,Y轴的UIViewControllerWrapperView动画显示错误position,因此解决方案只是覆盖此行为并为动画提供正确的值.这是代码:

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

}
Run Code Online (Sandbox Code Playgroud)