[英]iOS spacing issue with translucent navigation bar
我目前正在使用带有3段UISegmentedControl
的UIViewcontroller,当单击时会切换显示的控制器。 此视图的导航栏和标签栏是半透明的。
我像这样初始化视图:
- (void)viewDidLoad {
[super viewDidLoad];
[self setAutomaticallyAdjustsScrollViewInsets:YES];
self.segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"View 1",@"View 2",@"View 3",nil]];
[self.segControl setTintColor:[[ConstantsSingleton sharedConstants] default_bg_Color]];
[self.segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[self.segControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
[self.segControl setSelectedSegmentIndex:0];
self.navigationItem.titleView = self.segControl;
//Setting up the first viewcontroller
UIViewController *vc = [self viewControllerForSegmentIndex:self.segControl.selectedSegmentIndex];
[self addChildViewController:vc];
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view];
self.currentViewController = vc;
}
contentView
是一个IB定义的UIView
,在所有方面都有0个前导和尾随(所以基本上它填充了父视图)。
我按以下方式切换viewcontrollers:
-(void)segmentChanged:(UISegmentedControl *)sender {
UIViewController *vc = [self viewControllerForSegmentIndex:sender.selectedSegmentIndex];
[self addChildViewController:vc];
[self transitionFromViewController:self.currentViewController toViewController:vc duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
vc.view.frame = self.contentView.bounds;
[self.currentViewController.view removeFromSuperview];
[self.contentView addSubview:vc.view];
} completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[self.currentViewController removeFromParentViewController];
self.currentViewController = vc;
}];
self.navigationItem.title = vc.title;
}
现在每当我使用不透明的导航栏和标签栏运行时,这都可以正常工作,但每当我尝试使用半透明导航栏和/或标签栏时,只有第一个视图调整大小/其插图正确调整为不在半透明导航后面栏和/或标签栏。 当它们出现在屏幕上时,第二个和第三个视图仍将显示在它们后面。 将哪个viewcontroller设置为第一个viewcontroller并不重要,都会导致相同的行为。
可能导致此问题的原因是,如果不解决手动内容设置调整,有办法解决此问题。
我建议在您查看的属性检查器中启用“扩展边缘”选项。
这是一个很好的stackoverflow文章,区分iOS 7及更高版本的各种布局设置:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.