D-N*_*ice 10 xcode objective-c ios ios6 ios7
我构建了我的应用程序,在iOS 6中有一个半透明的导航栏.我想利用iOS 7中的半透明状态栏并保持iOS 6中的应用程序,但我的内容总是在iOS 7的状态栏下面,底部缺少20px.我认为我可以进行非常繁琐的代码更改,检查设备是否具有iOS 7,然后相应地调整我的内容,但我担心这将是很多工作.
理想情况下,我想在每个视图控制器的视图顶部添加20px的填充,以便内容向下移动,并且在iOS 6上使用不透明的导航栏仍能正常运行.
我已经阅读了主题1 2上存在的主题,但没有提供的答案解决了我的问题.
我应该注意,我没有使用Interface Builder,所有的VC都是以编程方式创建的.
如果您正在使用auto layout,那么您需要做的就是Vertical Constraint从最顶层的视图中添加一个,Top Layout Guide如下所示,它应该注意顶部间距.

有关详细信息:https: //developer.apple.com/library/ios/qa/qa1797/_index.html
这就是我用20px(状态栏的高度)来填充视图顶部所做的一切.
我在AppDelegate的应用程序中使用了这段代码:didFinishLaunchingWithOptions:method
...
// container holds my root view controller
UINavigationController *container = [UINavigationController alloc] init...];
...
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { // iOS 7
// Create parent controller that will contain your existing root view controller's view shifted 20 px down to account for the status bar.
UIViewController *newRootController = [[UIViewController alloc] init];
// Add my old root view controller as a child
[newRootController addChildViewController:container];
// Add its view as a subview
[newRootController.view addSubview:container.view];
// Call this method because it does some configuration?
[container didMoveToParentViewController:newRootController];
// Now just position the view starting at point (0, 20)
UIView *aView = container.view;
NSDictionary *viewDictionary = NSDictionaryOfVariableBindings(aView);
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[aView]|" options:0 metrics:nil views:viewDictionary];
[newRootController.view addConstraints:constraints];
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[aView]|" options:0 metrics:nil views:viewDictionary];
[newRootController.view addConstraints:constraints];
self.window.rootViewController = newRootController;
} else { // pre iOS 7
self.window.rootViewController = container;
}
Run Code Online (Sandbox Code Playgroud)
现在,无论何时你在iOS 7中,一切都将存在于根视图控制器的视图中,该视图向下移动了20个像素.您只需在AppDelegate中执行此操作一次.
| 归档时间: |
|
| 查看次数: |
8799 次 |
| 最近记录: |