Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带2个导航条的导航控制器-如何调整推送视图控制器的框架?_Ios_Objective C_Uinavigationcontroller_Uikit_Uinavigationbar - Fatal编程技术网

Ios 带2个导航条的导航控制器-如何调整推送视图控制器的框架?

Ios 带2个导航条的导航控制器-如何调整推送视图控制器的框架?,ios,objective-c,uinavigationcontroller,uikit,uinavigationbar,Ios,Objective C,Uinavigationcontroller,Uikit,Uinavigationbar,我有一个UINavigationController,我需要在其中添加第二个UINavigationBar。这些条都不是半透明的。问题是,我放在这个导航控制器中的视图控制器部分被我的第二个导航栏覆盖。我应该在哪里调整这些视图控制器视图的帧,以使它们在可见时更改帧不会产生“闪烁”效果 编辑: 这在viewDidLoad中: UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,

我有一个UINavigationController,我需要在其中添加第二个UINavigationBar。这些条都不是半透明的。问题是,我放在这个导航控制器中的视图控制器部分被我的第二个导航栏覆盖。我应该在哪里调整这些视图控制器视图的帧,以使它们在可见时更改帧不会产生“闪烁”效果

编辑: 这在viewDidLoad中:

UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
secondaryNavBar.translucent = NO;
if ([secondaryNavBar respondsToSelector:@selector(setBarTintColor:)]) { //it has to work on iOS 6 as well
    secondaryNavBar.barTintColor = [UIColor darkGrayColor];
    secondaryNavBar.tintColor = [UIColor whiteColor];
}
else {
    secondaryNavBar.tintColor = [UIColor darkGrayColor];
}
[self.view addSubview:secondaryNavBar];
self.secondaryNavBar = secondaryNavBar;

这里有一个有效的解决方案。当然不是最好的,而且我也不是为了支持iOS 6而做的,你必须对它进行测试

CustomNavigationController.m:

@implementation CustomNavigationController {

    UINavigationBar *bottomNavBar;
}

- (void)viewDidLoad {

    [super viewDidLoad];        
    [self showNavBar];
}

- (void)showNavBar {

    UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
    secondaryNavBar.translucent = NO;
    if ([secondaryNavBar respondsToSelector:@selector(setBarTintColor:)]) { //it has to work on iOS 6 as well
        secondaryNavBar.barTintColor = [UIColor darkGrayColor];
        secondaryNavBar.tintColor = [UIColor whiteColor];
    }
    else {
        secondaryNavBar.tintColor = [UIColor darkGrayColor];
    }

    [self.view addSubview:secondaryNavBar];
    bottomNavBar = secondaryNavBar;

    [self layoutNavBar];
}

- (void)layoutNavBar {

    // Get the currently displayed view
    UIView *contentView = self.topViewController.view;
    // Get its frame and height
    CGRect contentFrame = contentView.frame;
    float height = contentFrame.size.height;

    // Adapt height and y origin with the new nav bar
    contentFrame.size.height = height - bottomNavBar.frame.size.height;
    contentFrame.origin.y = bottomNavBar.frame.origin.y + bottomNavBar.frame.size.height;

    // Set the view's frame
    contentView.frame = contentFrame;

}


@end
@implementation ViewController

-(void)viewDidAppear:(BOOL)animated {

    CustomNavigationController *navigation = (CustomNavigationController*)self.navigationController;
    [navigation layoutNavBar];
}

@end
ViewController.m:

@implementation CustomNavigationController {

    UINavigationBar *bottomNavBar;
}

- (void)viewDidLoad {

    [super viewDidLoad];        
    [self showNavBar];
}

- (void)showNavBar {

    UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
    secondaryNavBar.translucent = NO;
    if ([secondaryNavBar respondsToSelector:@selector(setBarTintColor:)]) { //it has to work on iOS 6 as well
        secondaryNavBar.barTintColor = [UIColor darkGrayColor];
        secondaryNavBar.tintColor = [UIColor whiteColor];
    }
    else {
        secondaryNavBar.tintColor = [UIColor darkGrayColor];
    }

    [self.view addSubview:secondaryNavBar];
    bottomNavBar = secondaryNavBar;

    [self layoutNavBar];
}

- (void)layoutNavBar {

    // Get the currently displayed view
    UIView *contentView = self.topViewController.view;
    // Get its frame and height
    CGRect contentFrame = contentView.frame;
    float height = contentFrame.size.height;

    // Adapt height and y origin with the new nav bar
    contentFrame.size.height = height - bottomNavBar.frame.size.height;
    contentFrame.origin.y = bottomNavBar.frame.origin.y + bottomNavBar.frame.size.height;

    // Set the view's frame
    contentView.frame = contentFrame;

}


@end
@implementation ViewController

-(void)viewDidAppear:(BOOL)animated {

    CustomNavigationController *navigation = (CustomNavigationController*)self.navigationController;
    [navigation layoutNavBar];
}

@end

请注意,您必须在
viewdide
上调用
layoutNavBar
,否则应用程序将重置视图的框架。这不是一个完全干净的解决方案,但却是一个很好的解决方案。

两个导航栏?真的是个好主意吗?我知道听起来很糟糕,但有点道理。在普通导航栏中,我必须始终在应用程序中的任何位置显示2个按钮,而第二个导航栏并不总是显示,它用于某些导航内容。是否将第二个导航栏添加到导航控制器?是的,它是我的UINavigationController子类的子视图。如果添加带有代码的导航栏,您可以发布它吗?这仍然会使视图控制器以“坏”大小滑入,并且当过渡动画结束时,它将在可见时调整大小。不幸的是,我不能这样做/