在iOS 7中模态具有翻转水平转换的视图控制器时,导航栏的位置错误

时间:2013-10-02 12:29:01

标签: cocoa-touch ios7 uinavigationbar

当我尝试在iOS7中模拟具有翻转水平过渡的视图控制器时,导航栏的原点在开始时为(0,0),然后在(0,20)处跳转到右侧位置。是否有可能使其在iOS6中表现相同?您可以下载项目here

我创建了一个自定义导航栏,如下所示:

@implementation MyCustomNavigationBar

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    UIImage *image = [UIImage imageNamed:@"Custom-Nav-Bar-BG.png"];


    [image drawInRect:CGRectMake(0,  0, self.frame.size.width, self.frame.size.height)];

    if (IOSVersion <7) {
    }else{
        self.translucent = NO;
        self.tintColor = [UIColor whiteColor];
        self.barStyle = UIBarStyleDefault;
        self.barTintColor = [UIColor redColor];

    }
}

@end

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:57)

我和你有同样的问题。我认为这是UIKit在iOS 7上的一个错误。

我在showWillAppear方法上添加了一些代码

     [self.navigationController.navigationBar.layer removeAllAnimations];

当我驳回这个观点时,我补充道:

-(IBAction)btnDonePressed:(id)sender {
    [UIView transitionWithView:self.navigationController.view
                      duration:0.75
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:nil
                    completion:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
}

这对我有用。希望这会对你有所帮助。

答案 1 :(得分:4)

而不是黑客[navigationBar.layer removeAllAnimations];,这样的事情也应该有效:

[UIView transitionWithView:self.view.window duration:FlipDuration options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
    [UIView performWithoutAnimation:^{
        [self presentViewController:modalController animated:NO completion:nil];
    }];
} completion:nil];

答案 2 :(得分:3)